build(aio): generate sitemap from the generated pages (#21689)
Closes #21684 PR Close #21689
This commit is contained in:

committed by
Miško Hevery

parent
2015ccd1f5
commit
a64af40c0b
@ -25,6 +25,7 @@ module.exports = new Package('angular-base', [
|
||||
// Register the processors
|
||||
.processor(require('./processors/generateKeywords'))
|
||||
.processor(require('./processors/createOverviewDump'))
|
||||
.processor(require('./processors/createSitemap'))
|
||||
.processor(require('./processors/checkUnbalancedBackTicks'))
|
||||
.processor(require('./processors/convertToJson'))
|
||||
.processor(require('./processors/fixInternalDocumentLinks'))
|
||||
|
15
aio/tools/transforms/angular-base-package/processors/createSitemap.js
vendored
Normal file
15
aio/tools/transforms/angular-base-package/processors/createSitemap.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
module.exports = function createSitemap() {
|
||||
return {
|
||||
$runAfter: ['paths-computed'],
|
||||
$runBefore: ['rendering-docs'],
|
||||
$process(docs) {
|
||||
docs.push({
|
||||
id: 'sitemap.xml',
|
||||
path: 'sitemap.xml',
|
||||
outputPath: '../sitemap.xml',
|
||||
template: 'sitemap.template.xml',
|
||||
urls: docs.filter(doc => doc.outputPath).map(doc => doc.path)
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
@ -0,0 +1,51 @@
|
||||
var testPackage = require('../../helpers/test-package');
|
||||
var Dgeni = require('dgeni');
|
||||
|
||||
describe('createSitemap processor', () => {
|
||||
var injector, processor;
|
||||
|
||||
beforeEach(() => {
|
||||
const dgeni = new Dgeni([testPackage('angular-base-package')]);
|
||||
|
||||
injector = dgeni.configureInjector();
|
||||
processor = injector.get('createSitemap');
|
||||
});
|
||||
|
||||
it('should be available from the injector', () => {
|
||||
expect(processor).toBeDefined();
|
||||
});
|
||||
|
||||
it('should run after "paths-computed"', () => {
|
||||
expect(processor.$runAfter).toEqual(['paths-computed']);
|
||||
});
|
||||
|
||||
it('should run before "rendering-docs"', () => {
|
||||
expect(processor.$runBefore).toEqual(['rendering-docs']);
|
||||
});
|
||||
|
||||
describe('$process', () => {
|
||||
describe('should add a sitemap doc', () => {
|
||||
|
||||
it('with the correct id, path, outputPath and template properties', () => {
|
||||
const docs = [];
|
||||
processor.$process(docs);
|
||||
expect(docs.pop()).toEqual(jasmine.objectContaining({
|
||||
id: 'sitemap.xml',
|
||||
path: 'sitemap.xml',
|
||||
outputPath: '../sitemap.xml',
|
||||
template: 'sitemap.template.xml'
|
||||
}));
|
||||
});
|
||||
|
||||
it('with an array of urls for each doc that has an outputPath', () => {
|
||||
const docs = [
|
||||
{ path: 'abc', outputPath: 'abc' },
|
||||
{ path: 'cde' },
|
||||
{ path: 'fgh', outputPath: 'fgh' },
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs.pop().urls).toEqual(['abc', 'fgh']);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user