Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
version link to API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
galenandrew committed Jan 16, 2016
1 parent 49904b6 commit 89ed8fe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
34 changes: 34 additions & 0 deletions generate-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

const Toc = require('markdown-toc')
const Fs = require('fs')
const Package = require('./package.json')

const internals = {
api: {
filename: './API.md',
contents: Fs.readFileSync('./API.md', 'utf8')
},
readme: {
filename: './README.md',
contents: Fs.readFileSync('./README.md', 'utf8')
}
}

const tocOptions = {
bullets: '-',
slugify: function (text) {
return text.toLowerCase()
.replace(/\s/g, '-')
.replace(/[^\w-]/g, '')
}
}

// generate table of contents and version label docs
const api = Toc.insert(internals.api.contents, tocOptions)
.replace(/<!-- version -->(.|\n)*<!-- versionstop -->/, `<!-- version -->\nAPI Documentation - \`v${Package.version}\`\n---\n<!-- versionstop -->`)
Fs.writeFileSync(internals.api.filename, api)

// create absolute URL for versioned docs
const readme = internals.readme.contents.replace(/\[API Documentation\]\(.*\)/g, `[API Documentation](${Package.homepage || ''}/blob/v${Package.version}/${internals.api.filename})`)
Fs.writeFileSync(internals.readme.filename, readme)
29 changes: 0 additions & 29 deletions generate-readme-toc.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"test": "npm run lint && lab -r console -t 100 -a code",
"test-ci": "standard && lab -r lcov -t 100 -a code | ./node_modules/.bin/coveralls",
"test-cov-html": "lab -r html -o coverage.html",
"toc": "node generate-readme-toc.js",
"version": "npm run toc && git add API.md"
"generate-docs": "node generate-docs.js",
"version": "npm run generate-docs && git add README.md API.md"
},
"engines": {
"node": ">= 4.0.0"
Expand Down

0 comments on commit 89ed8fe

Please sign in to comment.