Skip to content

Commit

Permalink
Build sitemaps (#51)
Browse files Browse the repository at this point in the history
* add build sitemaps script

* regenerated docs

* Add files via upload

* Add files via upload

* Delete google319a4ae362a3a60e.html

* Add files via upload

* avoid scss variable if it doesnt exist (#54)

* can now pass path for automatic docs route generation (#57)

* This diff support creation of tables of content for routes described in jsRoutes. (#56)

Previously, jsRoutes was taken as is - there was no reprocessing at all. All routes that needed to appear in the table of contents had to be in mdRoutes. The issue there is that mdRoutes mixed 2 kind of routes - those with documentations (as intended) and those with standalone components.
With this PR, we can go back to a model where mdRoutes contains only routes with markdown files (and can easily be generated instead of manually created)

* add build sitemaps script

* regenerated docs

* update sitemap syntax

* before rebasing
  • Loading branch information
jckr committed Aug 8, 2018
1 parent 268ba33 commit 4b5588b
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 204 deletions.
13 changes: 9 additions & 4 deletions base/components/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import fetch from 'fetch'
import Navigation from './Navigation'
import routes from 'routes'
import demos from 'demos'
import { HISTORY, PROJECT_TYPE, WEBSITE_PATH, PROJECT_URL } from 'config'
import { HISTORY, PROJECT_TYPE, PROJECT_URL } from 'config'
// Shim Prism to add JSX support
import 'prismjs/components/prism-jsx'

Expand Down Expand Up @@ -90,7 +90,7 @@ const makeEditMeLink = fileLocation => {
if (!fileLocation || PROJECT_TYPE !== 'github') {
return ''
}
const href = `${PROJECT_URL}/edit/master/${WEBSITE_PATH}${fileLocation}`
const href = `${PROJECT_URL}/edit/master/${fileLocation}`
.replace(/(\/+)/g, '/')
.replace(/^https:\//, 'https://')
return `<div class="edit-me">
Expand Down Expand Up @@ -179,8 +179,13 @@ class Markdown extends Component {

// output of the component: markdown of the page transcribed to HTML,
// with components if needed, and prev/next page buttons at the bottom
return (<div className={cx('fg', { markdown: !textOnly })}>{out}
<Navigation next={this.props.next} prev={this.props.prev} /></div>)

return (
<div className={cx('fg', { markdown: !textOnly })}>
{out}
<Navigation next={this.props.next} prev={this.props.prev} />
</div>
)
}
}

Expand Down
1 change: 0 additions & 1 deletion base/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ const flatRoutes = routesPrevNext.map(route => {
}
return route
})

export default [
{
path: '/',
Expand Down
25 changes: 0 additions & 25 deletions docs/bundle-76266e6c73bea44ec488.js

This file was deleted.

4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@



<link href="styles-76266e6c73bea44ec488.css" rel="stylesheet">
<link href="styles-51f3f8e82ea688d1e45b.css" rel="stylesheet">



Expand All @@ -56,7 +56,7 @@



<script src="bundle-76266e6c73bea44ec488.js" type="text/javascript"></script>
<script src="bundle-51f3f8e82ea688d1e45b.js" type="text/javascript"></script>



Expand Down
2 changes: 1 addition & 1 deletion docs/robots.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Sitemap: https://uber-web.github.io/ocular/sitemap.xml
sitemap: https://uber-web.github.io/ocular/sitemap.xml
42 changes: 21 additions & 21 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://uber-web.github.io/ocular/#/</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/</loc>
<priority>1</priority>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/basics/introduction</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/basics/introduction</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/basics/quick-start</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/basics/quick-start</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/build-your-own-components/presenting-oculars-base-components</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/build-your-own-components/presenting-oculars-base-components</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/build-your-own-components/2-app/appjs</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/build-your-own-components/2-app/appjs</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/build-your-own-components/2-app/headerjs</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/build-your-own-components/2-app/headerjs</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/build-your-own-components/2-app/tocjs</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/build-your-own-components/2-app/tocjs</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/build-your-own-components/3-home/homejs</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/build-your-own-components/3-home/homejs</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/build-your-own-components/3-home/herojs</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/build-your-own-components/3-home/herojs</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/build-your-own-components/3-home/footerjs</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/build-your-own-components/3-home/footerjs</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/build-your-own-components/markdown-component</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/build-your-own-components/markdown-component</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/build-your-own-components/search</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/build-your-own-components/search</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/configurating-ocular/configuration-reference</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/configurating-ocular/configuration-reference</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/routes-and-links-in-ocular/introduction-to-routes</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/routes-and-links-in-ocular/introduction-to-routes</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/routes-and-links-in-ocular/documentation-routes</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/routes-and-links-in-ocular/documentation-routes</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/routes-and-links-in-ocular/custom-pages</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/routes-and-links-in-ocular/custom-pages</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/routes-and-links-in-ocular/default-links</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/routes-and-links-in-ocular/default-links</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/routes-and-links-in-ocular/additional-links</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/routes-and-links-in-ocular/additional-links</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/styling-ocular/introduction-to-styling</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/styling-ocular/introduction-to-styling</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/styling-ocular/the-default-style-modules</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/styling-ocular/the-default-style-modules</loc>
</url>
<url>
<loc>https://uber-web.github.io/ocular/#/reference/styling-ocular/customizing-fonts</loc>
<loc>https://uber-web.github.io/ocular/?p=/#/documentation/reference/styling-ocular/customizing-fonts</loc>
</url>
</urlset>
1 change: 0 additions & 1 deletion docs/styles-76266e6c73bea44ec488.css

This file was deleted.

29 changes: 23 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
// THE SOFTWARE.

const { spawn, execSync } = require('child_process')
const { writeFileSync } = require('fs')
const { existsSync, readFileSync, writeFileSync } = require('fs')
const inquirer = require('inquirer')
const slug = require('slug')

const configTemplate = require('./templates/config')
const docTemplate = require('./templates/doc')
const mdRoutesTemplate = require('./templates/mdRoutes')
const optionsTemplate = require('./templates/build-routes-options')
const variablesTemplate = require('./templates/variables.scss')
const htmlConfigTemplate = require('./templates/html.config')

const { listDocs, buildMdRoutes } = require('./utils/build-docs')
const { listDocs, buildMdRoutes, buildSitemap } = require('./utils/build-docs')

const DIR_PATH = process.env.PWD

Expand Down Expand Up @@ -101,6 +102,7 @@ const commands = {
writeFileSync(`${DIR_PATH}/src/config.js`, configTemplate(res))
writeFileSync(`${DIR_PATH}/src/docs/getting-started.md`, docTemplate(res))
writeFileSync(`${DIR_PATH}/src/mdRoutes.js`, mdRoutesTemplate(res))
writeFileSync(`${DIR_PATH}/src/build-routes-options.json`, optionsTemplate(res))
writeFileSync(`${DIR_PATH}/src/demos.js`, 'export default {};\n')
writeFileSync(`${DIR_PATH}/src/styles/index.scss`, '')
writeFileSync(`${DIR_PATH}/src/styles/_variables.scss`, variablesTemplate())
Expand Down Expand Up @@ -135,10 +137,25 @@ const commands = {
},

'build-docs': () => {
const docsSrcPath = process.argv[3] || `${DIR_PATH}/src/docs/`
const docs = listDocs(docsSrcPath)
const output = buildMdRoutes(docs)

let options = {
websitePath: '/website'
}
if (existsSync(`${DIR_PATH}/src/build-routes-options.json`)) {
options = JSON.parse(readFileSync(`${DIR_PATH}/src/build-routes-options.json`))
}
const { websitePath, baseurl } = options
const docsSrcPath = process.argv[3] || options.docsSrcPath || `src/docs/`

const docs = listDocs(docsSrcPath, websitePath)
const output = buildMdRoutes(docs, docsSrcPath, websitePath)

if (baseurl) {
console.log('generating sitemap')
const sitemap = buildSitemap(baseurl, docs)
writeFileSync(`${DIR_PATH}/dist/sitemap.xml`, sitemap)
writeFileSync(`${DIR_PATH}/dist/robots.txt`, `sitemap: ${baseurl}/sitemap.xml`)
}
console.log('upating documentation routes')
writeFileSync(`${DIR_PATH}/src/mdRoutes.js`, output)
},

Expand Down
2 changes: 0 additions & 2 deletions templates/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export const PROJECTS = {};
export const FOOTER_LOGO = '';
export const WEBSITE_PATH = '${res.path}';
export const HOME_PATH = '/';
export const HOME_HEADING = '${res.desc}';
Expand Down
69 changes: 49 additions & 20 deletions utils/build-docs.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
const { existsSync, lstatSync, readdirSync, readFileSync } = require('fs')
const { basename, extname, resolve } = require('path')
const { basename, extname, join, normalize, relative } = require('path')
const { camel, sentence } = require('to-case')
const slug = require('slug')

const defaultDocumentationPath = '/documentation'

function listDocs(docsSrcPath) {
const absoluteDocsSrcPath = `${resolve(docsSrcPath)}/`
const queue = readdirSync(absoluteDocsSrcPath).map(fileName => ({
const queue = readdirSync(docsSrcPath).map(fileName => ({
fileName,
path: []
}))
const docs = []
while (queue.length) {
const { fileName, path } = queue.pop()
const fullPath = [absoluteDocsSrcPath]
.concat(path)
.concat(fileName)
.join('/')
.replace('//', '/')

const componentPath = path
.slice(1)
.concat(fileName)
.join('/')
const fullPath = normalize(
[docsSrcPath]
.concat(path)
.concat(fileName)
.join('/')
)

if (lstatSync(fullPath).isDirectory() === false) {
if (extname(fileName) === '.md') {
const docBaseNameFromFileName = basename(fileName, '.md')
Expand All @@ -36,7 +35,6 @@ function listDocs(docsSrcPath) {
docs.push({
docBaseName,
fileName,
componentPath,
componentName,
fullPath,
path
Expand All @@ -45,7 +43,7 @@ function listDocs(docsSrcPath) {
// ignore non .md files
} else {
const newPath = path.concat(fileName)
const newFullPath = [absoluteDocsSrcPath].concat(newPath).join('/')
const newFullPath = [docsSrcPath].concat(newPath).join('/')
readdirSync(newFullPath).forEach(f => {
queue.push({ fileName: f, path: newPath })
})
Expand All @@ -54,20 +52,25 @@ function listDocs(docsSrcPath) {
return docs
}

function buildMdRoutes(docs) {
function buildMdRoutes(docs, docsSrcPath, websitePath) {
const fileLocationBase = normalize(join(websitePath, docsSrcPath))
const componentPathBase = relative(join(websitePath, '/src'), fileLocationBase)

const result = {
name: 'Documentation',
path: '/documentation',
path: defaultDocumentationPath,
data: []
}

const output = []
docs
.sort((a, b) => (a.fullPath > b.fullPath ? 1 : -1))
.forEach(({ docBaseName, fileName, componentName, componentPath, path }) => {
.forEach(({ docBaseName, fileName, componentName, path }) => {
const componentPath = normalize(join(componentPathBase, path.join('/'), fileName))
const imp = `import ${componentName} from '${componentPath}'`
output.push(imp)

const pathSuffix = path.slice(2)
const pathSuffix = path
let destination = result.data
let currentPath = '/docs'

Expand All @@ -93,7 +96,7 @@ function buildMdRoutes(docs) {
})

destination.push({
fileLocation: `/src${currentPath}/${fileName}`,
fileLocation: normalize(join(fileLocationBase, path.join('/'), fileName)),
name: sentence(docBaseName),
markdown: componentName
})
Expand All @@ -111,7 +114,33 @@ function buildMdRoutes(docs) {
return output.join('\n')
}

function entry(base, path, priority) {
return [' <url>', ` <loc>${base}/?p=/#${path}</loc>`]
.concat(priority ? [` <priority>${priority}</priority>`] : [])
.concat([' </url>'])
}

function buildSitemap(base, docs) {
const sitemapStub = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
].concat(entry(base, '/', 1))

const output = docs
.reduce((prev, curr) => {
const path = [defaultDocumentationPath]
.concat(curr.path)
.concat(slug(curr.docBaseName, { lower: true }))
.join('/')
return prev.concat(entry(base, path))
}, sitemapStub)
.concat(['</urlset>'])

return output.join('\n')
}

module.exports = {
buildMdRoutes,
buildSitemap,
listDocs
}
4 changes: 2 additions & 2 deletions website/html.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {

baseurl: 'https://uber-web.github.io/ocular',
title: 'ocular-website',

meta: [{
name: 'description',
content: 'A documentation website for Ocular, made with Ocular',
}],

websitePath: '/website/'
};
4 changes: 4 additions & 0 deletions website/src/build-routes-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"websitePath": "/website",
"baseurl": "https://uber-web.github.io/ocular"
}
1 change: 1 addition & 0 deletions website/src/docs/BASEURL
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://uber-web.github.io/ocular
Loading

0 comments on commit 4b5588b

Please sign in to comment.