Skip to content

Commit

Permalink
chore(docs): add sitemap to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mishkolesnikov authored and malashkevich committed Jan 22, 2021
1 parent 123eb2b commit c59237c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"src/404.html",
"src/favicon.ico",
"src/favicon.png",
"src/google46533d2e7a851062.html"
"src/google46533d2e7a851062.html",
"src/robots.txt"
],
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.css",
Expand Down
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"clean": "rimraf dist",
"landing": "cp -r src/landing/ dist/",
"docs:dirs": "gulp create-docs-dirs",
"docs:sitemap": "gulp create-sitemap",
"build:prod": "npm run build -- docs --prod --aot --base-href '/react-native-ui-kitten/docs/'",
"gh-pages": "npm run ngh -- --dir ./dist"
},
Expand Down
1 change: 1 addition & 0 deletions docs/src/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sitemap: https://akveo.github.io/react-native-ui-kitten/sitemap.xml
47 changes: 47 additions & 0 deletions scripts/docs-dirs.ts → scripts/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { task } from 'gulp';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { isAbsolute, join, resolve, sep } from "path";
export const DOCS_DIST = './docs/dist';
export const DOCS_SITE_URL = 'https://akveo.github.io/react-native-ui-kitten/';

task('create-docs-dirs', (done) => {
const docsStructure = flatten('docs', routesTree(DOCS));
Expand All @@ -11,6 +12,37 @@ task('create-docs-dirs', (done) => {
done();
});

task('create-sitemap', (done) => {
const docsPages = flattenLeafs('docs', routesTree(DOCS));
createSitemap(docsPages);

done();
});


function createSitemap(docsPages) {
const sitemap = getSitemap(docsPages);
writeFileSync(join(DOCS_DIST, 'sitemap.xml'), sitemap);
}

function getSitemap(docsPages) {
return `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>${DOCS_SITE_URL}</loc>
</url>
${getUrlTags(docsPages)}
</urlset>`;
}

function getUrlTags(docsPages) {
return docsPages.map(pageUrl => {
return `
<url>
<loc>${DOCS_SITE_URL}${pageUrl}</loc>
</url>`;
}).join('');
}

function flatten(root, arr) {
let res: any[] = [];
Expand All @@ -25,6 +57,21 @@ function flatten(root, arr) {
return res;
}

function flattenLeafs(root, arr) {
let res: any[] = [];
arr.forEach((item: any) => {
const path = `${root}/${item.path}`;
if (!item.children || item.children.length === 0) {
res.push(path);
}
if (item.children) {
res = res.concat(flatten(path, item.children));
}
});

return res;
}

function createDirsStructure(dirs) {
const index = readFileSync(join(DOCS_DIST, '/docs/index.html'), 'utf8');
dirs.forEach((dir: any) => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import './bump-version';
import './parse-docs';
import './publish-docs';
import './publish-packages';
import './docs-dirs';
import './docs';
6 changes: 6 additions & 0 deletions scripts/publish-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
gulp.task('publish-docs', gulp.series(
rebuild,
createDocsDirs,
createDocsSitemap,
addLanding,
copyOldVersion,
copyLatestStableVersion,
Expand All @@ -25,6 +26,11 @@ function createDocsDirs(done: GulpCompletionCallback): void {
done();
}

function createDocsSitemap(done: GulpCompletionCallback): void {
execSync('npm run docs:sitemap', { cwd: DOCS_DIR });
done();
}

function addLanding(done: GulpCompletionCallback): void {
execSync('npm run landing', { cwd: DOCS_DIR });
done();
Expand Down

0 comments on commit c59237c

Please sign in to comment.