Skip to content

Instantly share code, notes, and snippets.

@zeke
Last active April 3, 2018 16:24
Show Gist options
  • Save zeke/b4477fa51af41ed5149e81338382d14c to your computer and use it in GitHub Desktop.
Save zeke/b4477fa51af41ed5149e81338382d14c to your computer and use it in GitHub Desktop.
const cheerio = require('cheerio')
const i18n = require('..')
const locales = Object.keys(i18n.locales)
function getNav(locale) {
const docs = i18n.docs[locale]
const readme = docs['/docs/README']
const html = readme.sections.map(section => section.html).join('\n')
const $ = cheerio.load(html)
const startHeading = $('h2')[1]
const listItems = $(startHeading).next('ul').html()
const toc = `<ul>${listItems}</ul>`
console.log(toc)
return toc
}
navs = locales.map(locale => {
return getNav(locales)
})
i18n.navs = navs
fs.writeFileSync(
path.join(__dirname, '../index.json'),
JSON.stringify(i18n, null, 2)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment