This repository was archived by the owner on Aug 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Local and external ordering #101
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c5a75fe
add support for order config
cd7a619
fix z-index issue on search results
10a0be6
allow sorting of external repos
5972ad7
merge local and external config
d94b06d
linting fixes
f7c2176
fix config, pull out sort function, adjust logging
0a610f2
use routify instead of slugify
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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/" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| # Our documentation is coming soon! | ||
| # Our documentation is coming soon! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,13 @@ async function hydrate (file, baseDir, outputDir, shouldGetContent) { | |
| return data | ||
| } | ||
|
|
||
| async function buildManifest (env, opts = {}) { | ||
| 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 = {} | ||
| const urlmap = {} | ||
|
|
@@ -69,34 +74,44 @@ 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 | ||
| ) | ||
|
|
||
| // 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}`) | ||
| 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 | ||
| urlmap[hydrated.url] = filemap[path] | ||
|
|
||
| if (hydrated.draft) { | ||
| return | ||
| } | ||
|
|
||
| return isIndex ? { | ||
| indexLink: hydrated.url, | ||
| order: hydrated.order, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need to be in the actual manifest? It should already be sorted by the time it gets passed to the theme app. |
||
| } : { | ||
| text: hydrated.title, | ||
| link: hydrated.url, | ||
| order: hydrated.order, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -112,11 +127,14 @@ async function buildManifest (env, opts = {}) { | |
| return { | ||
| text: ourpath.titlify(path), | ||
| link: indexItem ? indexItem.indexLink : undefined, | ||
| order: indexItem ? indexItem.order : null, | ||
| 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(sortByOrder) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -133,14 +151,15 @@ async function buildManifest (env, opts = {}) { | |
| children: navtreeExternal, | ||
| } = await _walk(opts.reposDir, ignoredUnderscores) | ||
|
|
||
| // Combine and sort local and external nav trees | ||
| const navtree = [...navtreeLocal, ...navtreeExternal] | ||
| .sort(sortByOrder) | ||
|
|
||
| return { | ||
| files, | ||
| filemap, | ||
| urlmap, | ||
| navtree: [ | ||
| ...navtreeLocal, | ||
| ...navtreeExternal, | ||
| ], | ||
| navtree, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -150,10 +169,12 @@ 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), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| 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 => ({ | ||
| [`/${routify(e.name)}${k}`]: e.config.order[k] | ||
| })) | ||
| .reduce((acc, cur) => ({ ...acc, ...cur }), {}) | ||
| config.order = { ...order, ...config.order } | ||
| }) | ||
|
|
||
| return config | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality should be extended from
src/utils/config.js. There is already a_readConfigFileand_getConfigFilenamethat should be used, since they do a little more.