build(aio): generate sitemap from the generated pages (#21689)
Closes #21684 PR Close #21689
This commit is contained in:
parent
2015ccd1f5
commit
a64af40c0b
|
@ -1,3 +1,4 @@
|
||||||
# Allow all URLs (see http://www.robotstxt.org/robotstxt.html)
|
# Allow all URLs (see http://www.robotstxt.org/robotstxt.html)
|
||||||
User-agent: *
|
User-agent: *
|
||||||
Disallow:
|
Disallow:
|
||||||
|
Sitemap: https://angular.io/generated/sitemap.xml
|
||||||
|
|
|
@ -25,6 +25,7 @@ module.exports = new Package('angular-base', [
|
||||||
// Register the processors
|
// Register the processors
|
||||||
.processor(require('./processors/generateKeywords'))
|
.processor(require('./processors/generateKeywords'))
|
||||||
.processor(require('./processors/createOverviewDump'))
|
.processor(require('./processors/createOverviewDump'))
|
||||||
|
.processor(require('./processors/createSitemap'))
|
||||||
.processor(require('./processors/checkUnbalancedBackTicks'))
|
.processor(require('./processors/checkUnbalancedBackTicks'))
|
||||||
.processor(require('./processors/convertToJson'))
|
.processor(require('./processors/convertToJson'))
|
||||||
.processor(require('./processors/fixInternalDocumentLinks'))
|
.processor(require('./processors/fixInternalDocumentLinks'))
|
||||||
|
|
|
@ -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']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
|
{%- for url in doc.urls %}
|
||||||
|
<url>
|
||||||
|
<loc>https://angular.io/{$ url $}</loc>
|
||||||
|
</url>{% endfor %}
|
||||||
|
</urlset>
|
Loading…
Reference in New Issue