pidgin/nest

Add pgp public key and refer to it in our security disclosure method

The idea behind this is to make sure people that choose to use email to let us
known about a potential security issue in Pidgin encrypt the content of the
emails using a set of pgp keys of trusted Pidgin developers. For now we only
have the pgp key of grim but more keys can easily be added later on.

At the same time, since Hugo does not currently have a built-in shortcode for
linking directly to static resources, I had to add a new shortcode for doing so

Testing Done:
Ran `dev-server.sh` and made sure content looked as intended and links worked.

Bugs closed: NEST-46

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