From c5a75fe7394d5349fa6ee89394166465ca67e3df Mon Sep 17 00:00:00 2001 From: Zach Sherman Date: Sun, 13 May 2018 11:19:33 -0400 Subject: [PATCH 1/7] add support for order config --- docs/externals.md | 2 ++ docs/index.md | 2 +- src/cmds/build.js | 2 +- src/cmds/serve.js | 6 ++-- src/core/externals.js | 10 +++++++ src/core/manifest.js | 47 +++++++++++++++++++++++--------- src/core/static.js | 3 ++ src/core/syntax.js | 3 +- src/utils/config.js | 1 + themes/default/search/styles.js | 2 +- themes/default/sidebar/styles.js | 3 +- 11 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 docs/externals.md diff --git a/docs/externals.md b/docs/externals.md new file mode 100644 index 0000000..9de4e59 --- /dev/null +++ b/docs/externals.md @@ -0,0 +1,2 @@ +{ "name": "Node", "url": "https://github.com/timberio/timber-node.git", "branch": "docs/gitdocs", "root": "docs/" }, +{ "name": "Elixir", "url": "https://github.com/timberio/timber-elixir.git", "branch": "master", "root": "docs/" } \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 85c3155..6159ff3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1 +1 @@ -# Our documentation is coming soon! +# Our documentation is coming soon! \ No newline at end of file diff --git a/src/cmds/build.js b/src/cmds/build.js index e0ee007..1012b97 100644 --- a/src/cmds/build.js +++ b/src/cmds/build.js @@ -9,7 +9,7 @@ module.exports = async (args, config) => { const env = 'production' const bundleBar = progress({ clear: true, total: 100 }) - log('Bundling the Javascript app') + log('[\u2713] Bundling the Javascript app') await fs.emptyDir(config.output) const { props, compiler } = await runCore(env, config, bundleBar) diff --git a/src/cmds/serve.js b/src/cmds/serve.js index 8d4d894..12cde54 100644 --- a/src/cmds/serve.js +++ b/src/cmds/serve.js @@ -4,17 +4,17 @@ const { styles, log, progress, fullScreen } = require('../utils/emit') module.exports = async (args, config) => { fullScreen() - log('Starting local development server', true) + log('[\u2713] Starting local development server', true) const env = 'development' const bar = progress({ total: 100, clear: true }) - log('Bundling the Javascript app') + log('[\u2713] Bundling the Javascript app') const { props, compiler } = await runCore(env, config, bar) const server = await startServer(env, compiler, props) - log(`We are live at ${styles.url(server.url)}`) + log(`[\u2713] Docs are live at ${styles.url(server.url)}`) } module.exports.menu = ` diff --git a/src/core/externals.js b/src/core/externals.js index 2d71fde..8aa689d 100644 --- a/src/core/externals.js +++ b/src/core/externals.js @@ -73,16 +73,26 @@ function extractDocs (reposDir, externalsDir, sources) { return warn(`No docs root found for ${s.name || 'source'}, skipping...`) } + // Get external docs config, will be merged with cwd config + const configPath = `${docsRoot}/.gitdocs.json` + const configFileExists = fs.existsSync(configPath) + const config = configFileExists ? fs.readJson(configPath) : {} + // Add to the list of valid external doc sources externals.push({ name: s.name, path: outputPath, + config, }) // Move the external docs repo to our tmp folder fs.copySync(docsRoot, outputPath) }) + if (externals.length) { + log('[\u2713] External docs loaded') + } + return externals } diff --git a/src/core/manifest.js b/src/core/manifest.js index 7993639..b1f2497 100644 --- a/src/core/manifest.js +++ b/src/core/manifest.js @@ -35,11 +35,10 @@ async function warnForIndexConflict (file) { } } -async function hydrate (file, baseDir, outputDir, shouldGetContent) { - const data = await getFrontmatter(file) - +async function hydrate (data, file, baseDir, outputDir, shouldGetContent, config) { data.url = ourpath.routify(data.url || file, baseDir) data.title = data.title || ourpath.titlify(data.url) + data.order = data.order || config.order[data.url.replace(/\/$/, "")] || null data.file = file data.fileOutput = ourpath.outputify(`${outputDir}${data.url}`, { @@ -53,7 +52,7 @@ async function hydrate (file, baseDir, outputDir, shouldGetContent) { return data } -async function buildManifest (env, opts = {}) { +async function buildManifest (env, config, opts = {}) { const files = [] const filemap = {} const urlmap = {} @@ -69,17 +68,26 @@ async function buildManifest (env, opts = {}) { } if (stats.isFile()) { + // Only watch for certain file extensions (defaults to *.md) if (opts.extensions && opts.extensions.indexOf(ext) === -1) { return null } + // Warn if there are any route index conflicts await warnForIndexConflict(path) await checkForIndexConflict(path) + // @TODO: Check fro Readme.md or [folder].md const isIndex = /\/index\.[\w]+$/.test(path) const shouldGetContent = env === 'production' - const hydrated = await hydrate(path, dir, opts.outputDir, shouldGetContent) + const frontMatter = await getFrontmatter(path) + const hydrated = await hydrate(frontMatter, path, dir, opts.outputDir, shouldGetContent, config) + console.log(hydrated.order) + + // Ignore files with a `draft` status + if (frontMatter.draft) return + // Detect duplicate URLs if (urlmap[hydrated.url]) { const duplicated = files[urlmap[hydrated.url]].file throw new Error(`Can't use a URL more than once: ${hydrated.url}\n\t- ${duplicated}\n\t- ${hydrated.file}`) @@ -88,15 +96,15 @@ async function buildManifest (env, opts = {}) { filemap[path] = files.push(hydrated) - 1 urlmap[hydrated.url] = filemap[path] - if (hydrated.draft) { - return - } - return isIndex ? { indexLink: hydrated.url, + order: hydrated.order, + data: frontMatter, } : { text: hydrated.title, link: hydrated.url, + order: hydrated.order, + data: frontMatter } } @@ -112,11 +120,19 @@ async function buildManifest (env, opts = {}) { return { text: ourpath.titlify(path), link: indexItem ? indexItem.indexLink : undefined, + order: indexItem ? indexItem.order : null, + data: indexItem ? indexItem.data : {}, children: children .filter(Boolean) .filter(({ indexLink }) => !indexLink) - // sort children alphabetically - .sort((a, b) => a.text > b.text), + // Sort alphabetically + .sort((a, b) => a.text > b.text) + // Sort by order in config or frontmatter + .sort((a, b) => { + if (a.order === null && b.order !== null) return 1 + if (b.order === null && a.order !== null) return -1 + return a.order - b.order + }) } } } @@ -150,16 +166,21 @@ module.exports = async (env, config) => { } if (/^\//.test(config.root)) { - throw new Error(`Root is set to an absolute path! Did you mean ".${config.root}" instead of "${config.root}"?`) + throw new Error( + `Root is set to an absolute path! Did you mean ".${config.root}" instead of "${config.root}"?` + ) } - const manifest = await buildManifest(env, { + const manifest = await buildManifest(env, config, { dir: syspath.resolve(config.root), reposDir: syspath.resolve(config.temp, namespaces.repos), outputDir: syspath.resolve(config.output), extensions: ['.md'], }) + // fs.writeFile("./tree.json", JSON.stringify(dirtree(syspath.resolve(config.root)))) + // console.log(JSON.stringify(manifest.navtree, 0, 2)) + if (manifest.urlmap['/'] === undefined) { warn('No index file was found! Create an `index.md` at the root of your project.') } diff --git a/src/core/static.js b/src/core/static.js index 43d1685..33d37ea 100644 --- a/src/core/static.js +++ b/src/core/static.js @@ -2,6 +2,7 @@ const fs = require('fs-extra') const syspath = require('path') const chokidar = require('chokidar') const { namespaces } = require('../utils/temp') +const log = require('../utils/emit') function _watch (cwd, tempDir) { const watcher = chokidar.watch('**/*', { @@ -41,5 +42,7 @@ module.exports = async (config, useTempDir) => { await fs.copy(config.static, config.output) } + log('[\u2713] Static assets loaded') + return dir } diff --git a/src/core/syntax.js b/src/core/syntax.js index c9cc61a..cdc22c7 100644 --- a/src/core/syntax.js +++ b/src/core/syntax.js @@ -1,5 +1,6 @@ const fs = require('fs-extra') const syspath = require('path') +const { log } = require('../utils/emit') const { namespaces } = require('../utils/temp') const NODE_MODS = syspath.resolve(__dirname, '../../node_modules') @@ -23,6 +24,6 @@ module.exports = async (config) => { const path = `${temp}/${namespaces.codegen}/loadSyntax.js` await fs.outputFile(path, content) - + log('[\u2713] Syntax loaded') return path } diff --git a/src/utils/config.js b/src/utils/config.js index 1bbf20a..c6a40f1 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -32,6 +32,7 @@ const DEFAULT_CONFIG = { sidebar_links: [], header_links: [], sources: [], + order: {}, } function _getConfigFilename () { diff --git a/themes/default/search/styles.js b/themes/default/search/styles.js index bdf370c..bd48c19 100644 --- a/themes/default/search/styles.js +++ b/themes/default/search/styles.js @@ -22,7 +22,7 @@ export const Input = styled('input')` export const Results = styled('div')` position: absolute; width: 100%; - top: 75; + top: 75px; height: calc(100vh - 75px); background: #FFF; ` diff --git a/themes/default/sidebar/styles.js b/themes/default/sidebar/styles.js index 67fbb8f..8c3c496 100644 --- a/themes/default/sidebar/styles.js +++ b/themes/default/sidebar/styles.js @@ -107,8 +107,9 @@ export const NavItem = styled(Accordion)` font-weight: 700; text-decoration: none; cursor: pointer; - line-height: 30px; + line-height: 24px; border-left: 3px solid transparent; + padding: .1rem 1rem .1rem 0; :hover { opacity: 0.7; } From cd7a6192960d4205e05b09683a1cb261349e3a07 Mon Sep 17 00:00:00 2001 From: Zach Sherman Date: Sun, 13 May 2018 17:30:01 -0400 Subject: [PATCH 2/7] fix z-index issue on search results --- themes/default/search/styles.js | 1 + 1 file changed, 1 insertion(+) diff --git a/themes/default/search/styles.js b/themes/default/search/styles.js index bd48c19..5bfcb7f 100644 --- a/themes/default/search/styles.js +++ b/themes/default/search/styles.js @@ -25,6 +25,7 @@ export const Results = styled('div')` top: 75px; height: calc(100vh - 75px); background: #FFF; + z-index: 99; ` export const Result = styled('div')` From 10a0be6da28e5a466da4a2df2e407e97e2a494cf Mon Sep 17 00:00:00 2001 From: Zach Sherman Date: Sun, 13 May 2018 18:02:10 -0400 Subject: [PATCH 3/7] allow sorting of external repos --- src/core/index.js | 2 +- src/core/manifest.js | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/core/index.js b/src/core/index.js index 4a232b4..cc67320 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,7 +6,7 @@ const getCompiler = require('./compiler') module.exports = async (env, config, bar) => { await loadSyntax(config) - await getExternals(config) + const externals = await getExternals(config) await staticAssets(config, env === 'development') const manifest = await getManifest(env, config) diff --git a/src/core/manifest.js b/src/core/manifest.js index b1f2497..8675fcb 100644 --- a/src/core/manifest.js +++ b/src/core/manifest.js @@ -82,7 +82,6 @@ async function buildManifest (env, config, opts = {}) { const shouldGetContent = env === 'production' const frontMatter = await getFrontmatter(path) const hydrated = await hydrate(frontMatter, path, dir, opts.outputDir, shouldGetContent, config) - console.log(hydrated.order) // Ignore files with a `draft` status if (frontMatter.draft) return @@ -117,6 +116,10 @@ async function buildManifest (env, config, opts = {}) { const indexItem = children .find(item => item && item.indexLink) + if (indexItem) { + console.log(indexItem.indexLink, indexItem.order) + } + return { text: ourpath.titlify(path), link: indexItem ? indexItem.indexLink : undefined, @@ -149,14 +152,19 @@ async function buildManifest (env, config, opts = {}) { children: navtreeExternal, } = await _walk(opts.reposDir, ignoredUnderscores) + // Combine and sort local and external nav trees + const navtree = [...navtreeLocal, ...navtreeExternal] + .sort((a, b) => { + if (a.order === null && b.order !== null) return 1 + if (b.order === null && a.order !== null) return -1 + return a.order - b.order + }) + return { files, filemap, urlmap, - navtree: [ - ...navtreeLocal, - ...navtreeExternal, - ], + navtree, } } From 5972ad7b7f749e4bdc78546858afd5c6d8b5a750 Mon Sep 17 00:00:00 2001 From: Zach Sherman Date: Sun, 13 May 2018 19:36:19 -0400 Subject: [PATCH 4/7] merge local and external config --- src/core/externals.js | 4 ++-- src/core/index.js | 10 ++++++++++ src/core/merge.js | 15 +++++++++++++++ src/utils/path.js | 5 +++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/core/merge.js diff --git a/src/core/externals.js b/src/core/externals.js index 8aa689d..9e2c775 100644 --- a/src/core/externals.js +++ b/src/core/externals.js @@ -74,9 +74,9 @@ function extractDocs (reposDir, externalsDir, sources) { } // Get external docs config, will be merged with cwd config - const configPath = `${docsRoot}/.gitdocs.json` + const configPath = `${externalsDir}/${s.name}/.gitdocs.json` const configFileExists = fs.existsSync(configPath) - const config = configFileExists ? fs.readJson(configPath) : {} + const config = configFileExists ? fs.readJsonSync(configPath) : {} // Add to the list of valid external doc sources externals.push({ diff --git a/src/core/index.js b/src/core/index.js index cc67320..eed1910 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -3,12 +3,22 @@ const getExternals = require('./externals') const getManifest = require('./manifest') const staticAssets = require('./static') const getCompiler = require('./compiler') +const mergeConfig = require('./merge') module.exports = async (env, config, bar) => { + // Load only supported syntaxes to reduce bundle size await loadSyntax(config) + + // Fetch any external docs sources const externals = await getExternals(config) + + // Merge current and extenal configs + config = mergeConfig(config, externals) + + // Load static assets like images, scripts, css, etc. await staticAssets(config, env === 'development') + // Build the documentation manifest const manifest = await getManifest(env, config) // this gets passed to the theme app diff --git a/src/core/merge.js b/src/core/merge.js new file mode 100644 index 0000000..3b614cf --- /dev/null +++ b/src/core/merge.js @@ -0,0 +1,15 @@ +const { slugify } = require('../utils/path') + +module.exports = (config, externals) => { + externals.forEach(e => { + const order = Object + .keys(e.config.order || {}) + .map(k => ({ + [`/${slugify(e.name)}${k}`]: e.config.order[k] + })) + .reduce((acc, cur) => ({ ...acc, ...cur }), {}) + config.order = { ...order, ...config.order } + }) + + return config +} diff --git a/src/utils/path.js b/src/utils/path.js index a6e1da9..1af9612 100644 --- a/src/utils/path.js +++ b/src/utils/path.js @@ -46,8 +46,13 @@ function titlify (str) { .join(' ') } +function slugify (str) { + return str.toLowerCase().split(' ').join('-') +} + module.exports = { routify, outputify, titlify, + slugify, } From d94b06d3df9e3af3da98db947c71d08885878db7 Mon Sep 17 00:00:00 2001 From: Zach Sherman Date: Sun, 13 May 2018 19:41:48 -0400 Subject: [PATCH 5/7] linting fixes --- src/core/index.js | 6 +++--- src/core/manifest.js | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/core/index.js b/src/core/index.js index eed1910..3a3b9a4 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -13,17 +13,17 @@ module.exports = async (env, config, bar) => { const externals = await getExternals(config) // Merge current and extenal configs - config = mergeConfig(config, externals) + const mergedConfig = mergeConfig(config, externals) // Load static assets like images, scripts, css, etc. await staticAssets(config, env === 'development') // Build the documentation manifest - const manifest = await getManifest(env, config) + const manifest = await getManifest(env, mergedConfig) // this gets passed to the theme app const props = { - config, + mergedConfig, manifest, } diff --git a/src/core/manifest.js b/src/core/manifest.js index 8675fcb..7b3bb0f 100644 --- a/src/core/manifest.js +++ b/src/core/manifest.js @@ -38,7 +38,7 @@ async function warnForIndexConflict (file) { async function hydrate (data, file, baseDir, outputDir, shouldGetContent, config) { data.url = ourpath.routify(data.url || file, baseDir) data.title = data.title || ourpath.titlify(data.url) - data.order = data.order || config.order[data.url.replace(/\/$/, "")] || null + data.order = data.order || config.order[data.url.replace(/\/$/, '')] || null data.file = file data.fileOutput = ourpath.outputify(`${outputDir}${data.url}`, { @@ -81,7 +81,9 @@ async function buildManifest (env, config, opts = {}) { const isIndex = /\/index\.[\w]+$/.test(path) const shouldGetContent = env === 'production' const frontMatter = await getFrontmatter(path) - const hydrated = await hydrate(frontMatter, path, dir, opts.outputDir, shouldGetContent, config) + const hydrated = await hydrate( + frontMatter, path, dir, opts.outputDir, shouldGetContent, config + ) // Ignore files with a `draft` status if (frontMatter.draft) return @@ -89,7 +91,9 @@ async function buildManifest (env, config, opts = {}) { // Detect duplicate URLs if (urlmap[hydrated.url]) { const duplicated = files[urlmap[hydrated.url]].file - throw new Error(`Can't use a URL more than once: ${hydrated.url}\n\t- ${duplicated}\n\t- ${hydrated.file}`) + throw new Error( + `Can't use a URL more than once: ${hydrated.url}\n\t- ${duplicated}\n\t- ${hydrated.file}` + ) } filemap[path] = files.push(hydrated) - 1 @@ -186,9 +190,6 @@ module.exports = async (env, config) => { extensions: ['.md'], }) - // fs.writeFile("./tree.json", JSON.stringify(dirtree(syspath.resolve(config.root)))) - // console.log(JSON.stringify(manifest.navtree, 0, 2)) - if (manifest.urlmap['/'] === undefined) { warn('No index file was found! Create an `index.md` at the root of your project.') } From f7c2176ffeb313058218aca5cc97e8a1e14d3404 Mon Sep 17 00:00:00 2001 From: Zach Sherman Date: Mon, 14 May 2018 15:59:34 -0400 Subject: [PATCH 6/7] fix config, pull out sort function, adjust logging --- src/cmds/build.js | 2 +- src/cmds/serve.js | 4 ++-- src/core/externals.js | 5 ++--- src/core/index.js | 14 +++++++------- src/core/manifest.js | 22 ++++++++-------------- src/core/static.js | 2 +- src/index.js | 2 +- src/utils/config.js | 28 ++++++++++++++++++++++------ 8 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/cmds/build.js b/src/cmds/build.js index 1012b97..e0ee007 100644 --- a/src/cmds/build.js +++ b/src/cmds/build.js @@ -9,7 +9,7 @@ module.exports = async (args, config) => { const env = 'production' const bundleBar = progress({ clear: true, total: 100 }) - log('[\u2713] Bundling the Javascript app') + log('Bundling the Javascript app') await fs.emptyDir(config.output) const { props, compiler } = await runCore(env, config, bundleBar) diff --git a/src/cmds/serve.js b/src/cmds/serve.js index 12cde54..c368179 100644 --- a/src/cmds/serve.js +++ b/src/cmds/serve.js @@ -4,12 +4,12 @@ const { styles, log, progress, fullScreen } = require('../utils/emit') module.exports = async (args, config) => { fullScreen() - log('[\u2713] Starting local development server', true) + log('Starting local development server', true) const env = 'development' const bar = progress({ total: 100, clear: true }) - log('[\u2713] Bundling the Javascript app') + log('Bundling the Javascript app') const { props, compiler } = await runCore(env, config, bar) const server = await startServer(env, compiler, props) diff --git a/src/core/externals.js b/src/core/externals.js index 9e2c775..3354e47 100644 --- a/src/core/externals.js +++ b/src/core/externals.js @@ -2,6 +2,7 @@ const fs = require('fs-extra') const path = require('path') const git = require('simple-git/promise') const { namespaces } = require('../utils/temp') +const { getExternalConfig } = require('../utils/config') const { log, warn, error } = require('../utils/emit') // Warnings for missing source information @@ -74,9 +75,7 @@ function extractDocs (reposDir, externalsDir, sources) { } // Get external docs config, will be merged with cwd config - const configPath = `${externalsDir}/${s.name}/.gitdocs.json` - const configFileExists = fs.existsSync(configPath) - const config = configFileExists ? fs.readJsonSync(configPath) : {} + const config = getExternalConfig(externalsDir, s.name) // Add to the list of valid external doc sources externals.push({ diff --git a/src/core/index.js b/src/core/index.js index 3a3b9a4..a98bace 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -5,25 +5,25 @@ const staticAssets = require('./static') const getCompiler = require('./compiler') const mergeConfig = require('./merge') -module.exports = async (env, config, bar) => { +module.exports = async (env, localConfig, bar) => { // Load only supported syntaxes to reduce bundle size - await loadSyntax(config) + await loadSyntax(localConfig) // Fetch any external docs sources - const externals = await getExternals(config) + const externals = await getExternals(localConfig) // Merge current and extenal configs - const mergedConfig = mergeConfig(config, externals) + const config = mergeConfig(localConfig, externals) // Load static assets like images, scripts, css, etc. - await staticAssets(config, env === 'development') + await staticAssets(localConfig, env === 'development') // Build the documentation manifest - const manifest = await getManifest(env, mergedConfig) + const manifest = await getManifest(env, config) // this gets passed to the theme app const props = { - mergedConfig, + config, manifest, } diff --git a/src/core/manifest.js b/src/core/manifest.js index 7b3bb0f..95c8238 100644 --- a/src/core/manifest.js +++ b/src/core/manifest.js @@ -52,6 +52,12 @@ async function hydrate (data, file, baseDir, outputDir, shouldGetContent, config return data } +function sortByOrder (a, b) { + if (a.order === null && b.order !== null) return 1 + if (b.order === null && a.order !== null) return -1 + return a.order - b.order +} + async function buildManifest (env, config, opts = {}) { const files = [] const filemap = {} @@ -120,10 +126,6 @@ async function buildManifest (env, config, opts = {}) { const indexItem = children .find(item => item && item.indexLink) - if (indexItem) { - console.log(indexItem.indexLink, indexItem.order) - } - return { text: ourpath.titlify(path), link: indexItem ? indexItem.indexLink : undefined, @@ -135,11 +137,7 @@ async function buildManifest (env, config, opts = {}) { // Sort alphabetically .sort((a, b) => a.text > b.text) // Sort by order in config or frontmatter - .sort((a, b) => { - if (a.order === null && b.order !== null) return 1 - if (b.order === null && a.order !== null) return -1 - return a.order - b.order - }) + .sort(sortByOrder) } } } @@ -158,11 +156,7 @@ async function buildManifest (env, config, opts = {}) { // Combine and sort local and external nav trees const navtree = [...navtreeLocal, ...navtreeExternal] - .sort((a, b) => { - if (a.order === null && b.order !== null) return 1 - if (b.order === null && a.order !== null) return -1 - return a.order - b.order - }) + .sort(sortByOrder) return { files, diff --git a/src/core/static.js b/src/core/static.js index 33d37ea..da522bb 100644 --- a/src/core/static.js +++ b/src/core/static.js @@ -2,7 +2,7 @@ const fs = require('fs-extra') const syspath = require('path') const chokidar = require('chokidar') const { namespaces } = require('../utils/temp') -const log = require('../utils/emit') +const { log } = require('../utils/emit') function _watch (cwd, tempDir) { const watcher = chokidar.watch('**/*', { diff --git a/src/index.js b/src/index.js index f7ae3f2..03c73aa 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ const getArguments = require('./utils/arguments') -const getConfig = require('./utils/config') +const { getConfig } = require('./utils/config') const { error } = require('./utils/emit') module.exports = async () => { diff --git a/src/utils/config.js b/src/utils/config.js index c6a40f1..266a755 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -35,11 +35,11 @@ const DEFAULT_CONFIG = { order: {}, } -function _getConfigFilename () { +function getConfigFilename () { return FILENAMES.find(fs.pathExistsSync) } -function _readConfigFile (file) { +function readConfigFile (file) { const ext = syspath.extname(file) return ext === '.js' @@ -47,7 +47,18 @@ function _readConfigFile (file) { : fs.readJson(file) } -module.exports = async (customFile) => { +function getExternalConfigFilename (dir, name) { + return FILENAMES + .map(f => `${dir}/${name}/${f}`) + .find(fs.pathExistsSync) +} + +function getExternalConfig (dir, name) { + const file = getExternalConfigFilename(dir, name) + return file ? readConfigFile(file) : {} +} + +async function getConfig (customFile) { // prioritize custom config file if passed, // but still fallback to default files if (customFile) { @@ -58,8 +69,8 @@ module.exports = async (customFile) => { } } - const configFile = _getConfigFilename() - const userConfig = configFile ? await _readConfigFile(configFile) : {} + const configFile = getConfigFilename() + const userConfig = configFile ? await readConfigFile(configFile) : {} // return deepmerge(DEFAULT_CONFIG, userConfig) const masterConfig = { @@ -79,8 +90,13 @@ module.exports = async (customFile) => { return masterConfig } +module.exports = { + getConfig, + getExternalConfig +} + module.exports.createConfig = async (name, root) => { - if (_getConfigFilename()) { + if (getConfigFilename()) { throw new Error('GitDocs is already initialized in this folder!') } From 0a610f22dd6fad59f2aa43d73e45e3996697df36 Mon Sep 17 00:00:00 2001 From: Zach Sherman Date: Mon, 14 May 2018 16:02:58 -0400 Subject: [PATCH 7/7] use routify instead of slugify --- src/core/manifest.js | 3 --- src/core/merge.js | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/manifest.js b/src/core/manifest.js index 95c8238..a212b30 100644 --- a/src/core/manifest.js +++ b/src/core/manifest.js @@ -108,12 +108,10 @@ async function buildManifest (env, config, opts = {}) { return isIndex ? { indexLink: hydrated.url, order: hydrated.order, - data: frontMatter, } : { text: hydrated.title, link: hydrated.url, order: hydrated.order, - data: frontMatter } } @@ -130,7 +128,6 @@ async function buildManifest (env, config, opts = {}) { text: ourpath.titlify(path), link: indexItem ? indexItem.indexLink : undefined, order: indexItem ? indexItem.order : null, - data: indexItem ? indexItem.data : {}, children: children .filter(Boolean) .filter(({ indexLink }) => !indexLink) diff --git a/src/core/merge.js b/src/core/merge.js index 3b614cf..8dd6ca6 100644 --- a/src/core/merge.js +++ b/src/core/merge.js @@ -1,11 +1,12 @@ -const { slugify } = require('../utils/path') +const { routify } = require('../utils/path') module.exports = (config, externals) => { externals.forEach(e => { + console.log(routify(e.name)) const order = Object .keys(e.config.order || {}) .map(k => ({ - [`/${slugify(e.name)}${k}`]: e.config.order[k] + [`/${routify(e.name)}${k}`]: e.config.order[k] })) .reduce((acc, cur) => ({ ...acc, ...cur }), {}) config.order = { ...order, ...config.order }