GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — nodejs.dev/scripts/transformNodeBlogPosts.js at main · nodejs/nodejs.dev
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Expand file tree/ Copy pathtransformNodeBlogPosts.jsMore file actions 90 lines (66 loc) · 2.53 KB / Copy pathtransformNodeBlogPosts.jsFile metadata and controls90 lines (66 loc) · 2.53 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 const fs = require('fs'); const yaml = require('yaml'); const path = require('path'); const async = require('async'); const dedent = require('dedent'); const blogAuthorsFile = fs.readFileSync( path.join(__dirname, '../src/data/blog/authors.yaml'), { encoding: 'utf-8' } ); const blogAuthors = yaml.parse(blogAuthorsFile); const applyBlogAuthors = metadataAuthors => metadataAuthors .split(' and ') .map(authorName => { const foundAuthor = blogAuthors.find( author => author.name === authorName ); return foundAuthor ? `'${foundAuthor.id}'` : authorName; }) .join(', '); // eslint-disable-next-line import/no-extraneous-dependencies const metadataParser = require('markdown-yaml-metadata-parser'); const commandLineArgs = process.argv.slice(2); const getMarkdownFilesPath = args => (args.length ? args[0] : '.'); const markdownPath = path.join(getMarkdownFilesPath(commandLineArgs)); const processMarkdownFile = (originalSlug, source) => { const { content, metadata } = metadataParser(source); const dateFromMetadata = new Date(metadata.date); const dateString = dateFromMetadata.toISOString().split('T')[0]; const newFileName = `${dateString}-${originalSlug}.md`; const metadataAuthors = metadata.author ? `[${applyBlogAuthors(metadata.author)}]` : `['node-js-website']`; const newContent = dedent` --- title: ${metadata.title} blogAuthors: ${metadataAuthors} category: '${metadata.category.toLowerCase()}' --- `; return { content: `${newContent}\n${content}`, filename: newFileName }; }; if (fs.existsSync(markdownPath)) { const filenames = fs.readdirSync(path.join(markdownPath)); const markdownFilesFromDirectory = filenames.filter( filename => filename.toLowerCase().includes('.md') && !filename.toLowerCase().includes('index.md') ); const blogQueue = async.queue((filename, callback) => { const markdownFile = path.join(markdownPath, filename); fs.readFile(markdownFile, { encoding: 'utf-8' }, (_, data) => { const originalSlug = filename.toLowerCase().replace('.md', ''); const { content, filename: newFileName } = processMarkdownFile( originalSlug, data ); const newMarkdownFile = path.join(markdownPath, newFileName); fs.unlink(markdownFile, () => {}); fs.writeFile(newMarkdownFile, content, () => callback()); }); }); blogQueue.push([...markdownFilesFromDirectory]); // eslint-disable-next-line no-console blogQueue.drain(() => console.log('Finished Processing')); } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |