* Tracks the progress of migrating content * from the the old site to the new site /***************************************************************************** *****************************************************************************/ const path = require('path') const front = require('front-matter') /***************************************************************************** *****************************************************************************/ const filepath = __dirname.replace(/\/tools(\/)?$/, '/hugo/content') const obsoleteRegex = /\s#(\s+)?obsolete(\s+)?$/i /***************************************************************************** *****************************************************************************/ .readFileSync(path.join(__dirname, 'paths.txt'), 'utf8') if (obsoleteRegex.test(path)) { obsoleted.push(path.replace(obsoleteRegex, '')) /** Information on new content */ const nestPages = getMdPaths(path.join(__dirname, '../hugo/content/')) // discard translated content .filter(path => !/\.\w+\.md$/.test(path)) const frontMatter = getFrontMatter(path) const replaces = castReplacesDataToArray(frontMatter.replaces) // convert to realative file path .replace(/\/_index(\.\w\w)?$/, ''), /***************************************************************************** *****************************************************************************/ 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), const percentComplete = ((countOfCovered / migrating.length) * 100).toPrecision( const countOfObsolete = paths.length - migrating.length tracking ${paths.length} pages ${countOfCovered}/${migrating.length} (${percentComplete}%) migrated ${countOfObsolete} obsoleted /***************************************************************************** * Generate redirection mapping *****************************************************************************/ // TODO: Generate redirection instructions /***************************************************************************** *****************************************************************************/ * Retrieves front matter from markdown files * @param {string} path path to mardown file function getFrontMatter(path) { const data = fs.readFileSync(path, 'utf8') const { attributes } = front(data) * creates a list of all markdown files in a directory * @param {string} directory directory to search for markdown files function getMdPaths(directory) { let items = fs.readdirSync(directory).map(i => path.join(directory, i)) const stat = fs.statSync(item) if (stat.isDirectory()) { const nueveau = fs.readdirSync(item).map(i => path.join(item, i)) } else if (stat.isFile() && mdRegex.test(item)) { * @param {void|string|string[]} replaces function castReplacesDataToArray(replaces) { } else if (typeof replaces === 'string') { } else if (Array.isArray(replaces)) { `expected replaces of ${path} to be falsey, string or an array`