pidgin/nest

a43164c34fb9
Add cross links to the plugins section

To do this, we had to move the text where we add the links away from the i18n
string list since Hugo does not support using shortcodes (e.g. for links) in
there.

Also added a new param that points to the docs page that explains our
contribution process (we'll reuse this new param in a later commit for the
development/contributing section of nest)

Testing Done:
Ran dev-server.sh and verified the content looks as intended and links worked

Reviewed at https://reviews.imfreedom.org/r/784/
/**
* Tracks the progress of migrating content
* from the the old site to the new site
*/
/*****************************************************************************
* Imports
*****************************************************************************/
const fs = require('fs')
const path = require('path')
const front = require('front-matter')
/*****************************************************************************
* Set Up
*****************************************************************************/
const filepath = __dirname.replace(/\/tools(\/)?$/, '/hugo/content')
const obsoleteRegex = /\s#(\s+)?obsolete(\s+)?$/i
const mdRegex = /\.md$/
const migrating = []
const obsoleted = []
/*****************************************************************************
* Execution
*****************************************************************************/
const paths = fs
.readFileSync(path.join(__dirname, 'paths.txt'), 'utf8')
.split('\r\n')
// Sift each URL
paths.forEach(path => {
if (obsoleteRegex.test(path)) {
obsoleted.push(path.replace(obsoleteRegex, ''))
} else {
migrating.push(path)
}
})
/** Information on new content */
const nestPages = getMdPaths(path.join(__dirname, '../hugo/content/'))
// discard translated content
.filter(path => !/\.\w+\.md$/.test(path))
.map(path => {
const frontMatter = getFrontMatter(path)
const replaces = castReplacesDataToArray(frontMatter.replaces)
return {
replaces,
path,
pathOnSite: path
// convert to relative file path
.replace(filepath, '')
// remove file extension
.replace(/\.md$/, '')
// remove _index
.replace(/\/_index(\.\w\w)?$/, ''),
}
})
/*****************************************************************************
* Generate Stats
*****************************************************************************/
const covered = new Set()
nestPages.forEach(page => page.replaces.forEach(path => covered.add(path)))
const countOfCovered = migrating.reduce(
(acc, path) => acc + (covered.has(path) ? 1 : 0),
0
)
const percentComplete = ((countOfCovered / migrating.length) * 100).toPrecision(
2
)
const countOfObsolete = paths.length - migrating.length
console.log(`
STATS:
tracking ${paths.length} pages
${countOfCovered}/${migrating.length} (${percentComplete}%) migrated
${countOfObsolete} obsoleted
`)
/*****************************************************************************
* Generate redirection mapping
*****************************************************************************/
// TODO: Generate redirection instructions
/*****************************************************************************
* Helpers
*****************************************************************************/
/**
* Retrieves front matter from markdown files
* @param {string} path path to markdown file
*/
function getFrontMatter(path) {
try {
const data = fs.readFileSync(path, 'utf8')
const { attributes } = front(data)
return attributes
} catch (error) {
console.log(error)
}
}
/**
* creates a list of all markdown files in a directory
* @param {string} directory directory to search for markdown files
*/
function getMdPaths(directory) {
let output = []
let items = fs.readdirSync(directory).map(i => path.join(directory, i))
while (items.length) {
const item = items.pop()
const stat = fs.statSync(item)
if (stat.isDirectory()) {
items.push(...fs.readdirSync(item).map(i => path.join(item, i)))
} else if (stat.isFile() && mdRegex.test(item)) {
output.push(item)
}
}
return output.sort()
}
/**
*
* @param {void|string|string[]} replaces
*/
function castReplacesDataToArray(replaces) {
if (!replaces) {
return []
} else if (typeof replaces === 'string') {
return [replaces]
} else if (Array.isArray(replaces)) {
return replaces
}
throw new Error(
`expected replaces of ${path} to be falsey, string or an array`
)
}