-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Generate an index from glossary terms with links to sections wh…
…ere they are being mentioned. (#3) Adds a new config option 'indexFile'. Details see README.md
- Loading branch information
1 parent
bb27d6c
commit bc94edb
Showing
7 changed files
with
85 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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,36 @@ | ||
const {relativeFromTo} = require("./pathplus"); | ||
const path = require("path"); | ||
|
||
const api = {}; | ||
let md = ""; | ||
|
||
api.writeIndex = function(context) { | ||
md = | ||
`# Index | ||
`; | ||
const {terms: dict, opts} = context; | ||
const {outDir, indexFile} = opts; | ||
const terms = dict.inOrder(); | ||
for (let i = 0, iLen = terms.length; i < iLen; i++) { | ||
const term = terms[i]; | ||
const text = term.term; | ||
const glossaryUrl = relativeFromTo( | ||
path.resolve(outDir, indexFile), | ||
path.resolve(outDir, term.glossary.file) | ||
) + term.anchor; | ||
md += | ||
` | ||
#### ${text} | ||
* [Glossary](${glossaryUrl}) | ||
`; | ||
const occurrences = terms[i].occurrences; | ||
for (url of Object.keys(occurrences)) { | ||
md += | ||
`* [${occurrences[url]}](${url}) | ||
`; | ||
} | ||
}; | ||
return md; | ||
} | ||
module.exports = api; |
This file contains 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 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 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 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