pidgin/nest

7c3b95c88023
Update "Mac OSX" references to "macOS"

Apple no longer calls their OS "Mac OSX" instead over the final releases of OSX they switched over to "macOS 10", followed by "macOS 11" and so on. With this change, we will start using macOS to refer to Apple's operating system.

Testing Done:
Ran `dev-server.sh` and verified content looked as intended.

Reviewed at https://reviews.imfreedom.org/r/825/
/**
* 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`
)
}