diff --git a/scripts/README.md b/scripts/README.md index d997c465..15c807c7 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -15,11 +15,11 @@ For example, to point all links to innersourcecommons.org: node substitute_article_urls.js isc ``` -## generate_jekyll_learning_path_markdown.js, generate_hugo_learning_path_markdown.js +## generate_learning_path_markdown.js -Node scripts to generate markdown files required for hosting Learning Path on innersourcecommons.org and innersourcecommons.net. +Node script to generate markdown files required for hosting Learning Path on innersourcecommons.org. -These scripts require a [GitHub access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token), as they use the GitHub API to get Learning Path contributors. Your token does not require any scopes, as the Learning Path is Open Source. To provide this, create a `.env` file in this directory in the following format: +This script requires a [GitHub access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token), as it uses the GitHub API to get Learning Path contributors. Your token does not require any scopes, as the Learning Path is Open Source. To provide this, create a `.env` file in this directory in the following format: ``` TOKEN= ``` @@ -27,47 +27,24 @@ TOKEN= ### Usage: ``` npm ci -node generate_jekyll_learning_path_markdown.js -node generate_hugo_learning_path_markdown.js +node generate_learning_path_markdown.js ``` ## How to update innersourcecommons.org with new articles -Anytime there are _new_ articles written, you need to run the script that generates the new pages on the [innersourcecommons.org] site. +Anytime there are _any changes_, you need to run the script that generates the updated pages on the [innersourcecommons.org] site. 1. Clone the [InnerSourceCommons/InnerSourceLearningPath] and [InnerSourceCommons/innersourcecommons.org] repos. 1. Is this the first time that articles have been written for this section in this language? -If so, then do both of the following: - - * update the ["sections" config](https://github.com/InnerSourceCommons/InnerSourceLearningPath/blob/master/scripts/section_data.json) with the language code of the articles for the appropriate section. -Open a pull request for the change. - * update the [Learning Path landing page](https://github.com/InnerSourceCommons/innersourcecommons.org/blob/master/resources/learningpath/index.md) with a link to your new language pages. - -3. Run **generate_jekyll_learning_path_markdown.js** as described above. -3. `cp -r learningpath/* /resources/learningpath/`. -3. Open a pull request with the modified files in the [InnerSourceCommons/innersourcecommons.org] repo. - -Note that these steps only needs to happen when there are new articles written. -Changes to existing articles will automatically show up on the [innersourcecommons.org] site. - -## How to update innersourcecommons.net - -Anytime there are _any changes_, you need to run the script that generates the updated pages on the [innersourcecommons.net] site. - -1. Clone the [InnerSourceCommons/InnerSourceLearningPath] and [InnerSourceCommons/innersourcecommons.net] repos. -1. Is this the first time that articles have been written for this section in this language? If so, then do both of the following: * update the ["sections" config](https://github.com/InnerSourceCommons/InnerSourceLearningPath/blob/master/scripts/section_data.json) with the language code of the articles for the appropriate section and open a pull request for the change * make sure this language appears in the [website config](https://github.com/InnerSourceCommons/innersourcecommons.net/blob/master/config.yaml) and there are the relevant [index pages](https://github.com/InnerSourceCommons/innersourcecommons.net/blob/master/content/learn/_index.ru.md) -3. Run `node substitute_article_urls.js isc.net` as described above. This changes the asciidoc source files' links to point at [innnersourcecommons.net] - do not commit this change! -3. Run **generate_hugo_learning_path_markdown.js** as described above. -3. `cp -r newsite/ /content/learn/learning-path/`. -3. Open a pull request with the modified files in the [InnerSourceCommons/innersourcecommons.net] repo. +3. Run **generate_learning_path_markdown.js** as described above. +3. `cp -r newsite/ /content/learn/learning-path/`. +3. Open a pull request with the modified files in the [InnerSourceCommons/innersourcecommons.org] repo. [innersourcecommons.org]: https://innersourcecommons.org/ -[innersourcecommons.net]: https://innersourcecommons.net/ [InnerSourceCommons/InnerSourceLearningPath]: https://github.com/InnerSourceCommons/InnerSourceLearningPath/ [InnerSourceCommons/innersourcecommons.org]: https://github.com/InnerSourceCommons/innersourcecommons.org -[InnerSourceCommons/innersourcecommons.net]: https://github.com/InnerSourceCommons/innersourcecommons.net diff --git a/scripts/generate_hugo_learning_path_markdown.js b/scripts/generate_hugo_learning_path_markdown.js deleted file mode 100644 index bca764b9..00000000 --- a/scripts/generate_hugo_learning_path_markdown.js +++ /dev/null @@ -1,55 +0,0 @@ -// TODO: GitHub Actions - more pertinent now article is rendered at build time not run time - -(async() => { - const fs = require('fs') - const YAML = require('yaml') - const { join } = require('path') - const asciidoctor = require('asciidoctor')() - const writeMarkdownFile = require('./write_markdown_file') - const generate = require('./generate_learning_path_markdown') - - const urls = YAML.parse(fs.readFileSync(join('..', 'config', 'urls.yaml'), 'utf-8')) - - const getYouTubeCode = (section, articleNumber) => { - const firstEntryOfGroupIndex = urls.findIndex(entry => entry.section === section.toLowerCase()) - const currentPageIndexOffset = articleNumber - 1 - const youtubeUrl = urls[firstEntryOfGroupIndex + currentPageIndexOffset].video.youtube - return youtubeUrl.replace('https://www.youtube.com/watch?v=', '') - } - - const generatorFn = ({ isTranslation, baseWritePath, articleNumber, translation, articleTitle, contributors, image, section, article}) => { - const fileName = isTranslation ? join(baseWritePath, [articleNumber, translation, 'md'].join('.')) : join(baseWritePath, [articleNumber, 'md'].join('.')) - const weight = parseInt(articleNumber) - const youtubeCode = getYouTubeCode(section.learning_path_group, weight) - - const frontMatter = { - title: articleTitle, - contributors, - image: `https://img.youtube.com/vi/${youtubeCode}/mqdefault.jpg`, - featured: weight === 1, - weight, - youtubeCode - } - - const titleStripped = article.asciiDoc.replace(/== (.*)/, '') - const body = section.renderArticles || isTranslation ? asciidoctor.convert(titleStripped) : '' - - writeMarkdownFile(fileName, frontMatter, body) - } - - const workbookFn = ({ workbookFileName, contributors, section, workbookPosition }) => { - const workbookFrontMatter = { - title: 'Workbook', - contributors, - image: section.image, - weight: workbookPosition - } - - const workbookReadPath = join('..', 'workbook', section.workbook) - const body = asciidoctor.convert(fs.readFileSync(workbookReadPath, 'utf-8')) - - writeMarkdownFile(workbookFileName, workbookFrontMatter, body) - } - - generate('newsite', generatorFn, workbookFn, false) -})() diff --git a/scripts/generate_jekyll_learning_path_markdown.js b/scripts/generate_jekyll_learning_path_markdown.js deleted file mode 100644 index f17db471..00000000 --- a/scripts/generate_jekyll_learning_path_markdown.js +++ /dev/null @@ -1,43 +0,0 @@ -(async() => { - const writeMarkdownFile = require('./write_markdown_file') - const generate = require('./generate_learning_path_markdown') - const path = require('path') - - const generatorFn = ({ isTranslation, writePath, articleNumber, translation, articleTitle, contributors, section, article}) => { - const fileName = articleNumber === '01' ? path.join(writePath, 'index.md') : path.join(writePath, `${articleNumber}.md`) - - const frontMatter = { - layout: 'learning-path-page', - show_meta: false, - title: `Learning Path - ${section.learning_path_group} - ${articleTitle}`, - learning_path_article: section.renderArticles || isTranslation ? path.relative('..', article.filePath) : undefined, - learning_path_group: section.learning_path_group, - learning_path_menu_title: `${articleNumber} - ${articleTitle}`, - learning_path_position: parseInt(articleNumber), - learning_path_translation: translation, - no_video: isTranslation, // Videos not available translated. - contributors - } - - writeMarkdownFile(fileName, frontMatter) - } - - const workbookFn = ({ workbookFileName, contributors, section, workbookPosition }) => { - const workbookFrontMatter = { - layout: 'learning-path-page', - show_meta: false, - title: `Learning Path - ${section.learning_path_group} - Workbook`, - learning_path_article: `workbook/${section.workbook}`, - learning_path_group: section.learning_path_group, - learning_path_menu_title: `${section.learning_path_group} Workbook`, - learning_path_position: workbookPosition, - learning_path_translation: '', - no_video: true, - contributors - } - - writeMarkdownFile(workbookFileName, workbookFrontMatter) - } - - generate('learningpath', generatorFn, workbookFn, true) -})() diff --git a/scripts/generate_learning_path_markdown.js b/scripts/generate_learning_path_markdown.js index e1941cc6..148a8369 100644 --- a/scripts/generate_learning_path_markdown.js +++ b/scripts/generate_learning_path_markdown.js @@ -1,6 +1,8 @@ const { join, basename, relative } = require('path') const fs = require('fs') const yamlFront = require('yaml-front-matter') +const asciidoctor = require('asciidoctor')() +const YAML = require('yaml') const getContributors = require('./get_contributors') const mkdirSync = require('./mkdir_sync') @@ -18,7 +20,17 @@ const languageMap = { ru: 'Russian' } -module.exports = async (writeDir, generatorFn, workbookFn, isJekyllSite) => { +const urls = YAML.parse(fs.readFileSync(join('..', 'config', 'urls.yaml'), 'utf-8')) + +const getYouTubeCode = (section, articleNumber) => { + const firstEntryOfGroupIndex = urls.findIndex(entry => entry.section === section.toLowerCase()) + const currentPageIndexOffset = articleNumber - 1 + const youtubeUrl = urls[firstEntryOfGroupIndex + currentPageIndexOffset].video.youtube + return youtubeUrl.replace('https://www.youtube.com/watch?v=', '') +} + +(async () => { + const writeDir = 'newsite' mkdirSync(join('.', writeDir)) sections.forEach((section, sectionDataIndex) => { @@ -29,51 +41,50 @@ module.exports = async (writeDir, generatorFn, workbookFn, isJekyllSite) => { translations.concat('' /* The English original */).forEach(async (translation) => { const isTranslation = translation !== '' - const writePath = join(baseWritePath, translation) const readPath = join(baseReadPath, translation) const articles = getArticleFiles(readPath) - // Bad separation of concerns (Hugo/Jekyll specific logic shouldn't be here) but is temporary until Jekyll site is decomissioned - if (isJekyllSite) { - mkdirSync(writePath) - } else { - let indexReadPath = join(readPath, 'index.md') - const indexTranslated = fs.existsSync(indexReadPath) - if (!indexTranslated) { - // Default to English index page content - indexReadPath = join(baseReadPath, 'index.md') - } - const indexWritePath = isTranslation ? join(baseWritePath, `_index.${translation}.md`) : join(baseWritePath, '_index.md') - - let { indexContent, ...indexFrontMatter } = yamlFront.loadFront(fs.readFileSync(indexReadPath, 'utf-8'), { contentKeyName: 'indexContent' }) - indexFrontMatter.image = section.image - indexFrontMatter.contributors = await getContributors(relative('..', readPath)) - indexFrontMatter.weight = sectionDataIndex + let indexReadPath = join(readPath, 'index.md') + const indexTranslated = fs.existsSync(indexReadPath) + if (!indexTranslated) { + // Default to English index page content + indexReadPath = join(baseReadPath, 'index.md') + } + const indexWritePath = isTranslation ? join(baseWritePath, `_index.${translation}.md`) : join(baseWritePath, '_index.md') - if (!indexTranslated) { - // Add placeholder text if index is not translated - indexContent = `This text will be translated soon to ${languageMap[translation]}.${indexContent}` - } + let { indexContent, ...indexFrontMatter } = yamlFront.loadFront(fs.readFileSync(indexReadPath, 'utf-8'), { contentKeyName: 'indexContent' }) + indexFrontMatter.image = section.image + indexFrontMatter.contributors = await getContributors(relative('..', readPath)) + indexFrontMatter.weight = sectionDataIndex - writeMarkdownFile(indexWritePath, indexFrontMatter, indexContent) + if (!indexTranslated) { + // Add placeholder text if index is not translated + indexContent = `This text will be translated soon to ${languageMap[translation]}.${indexContent}` } + writeMarkdownFile(indexWritePath, indexFrontMatter, indexContent) + articles.forEach(async (article) => { const articleTitle = article.asciiDoc.match(/== (.*)/)[1] const articleNumber = basename(article.filePath).split('-')[0] const contributors = await getContributors(relative('..', article.filePath)) + const fileName = isTranslation ? join(baseWritePath, [articleNumber, translation, 'md'].join('.')) : join(baseWritePath, [articleNumber, 'md'].join('.')) + const weight = parseInt(articleNumber) + const youtubeCode = getYouTubeCode(section.learning_path_group, weight) - generatorFn({ - section, - articleTitle, - articleNumber, - isTranslation, - article, - translation, + const frontMatter = { + title: articleTitle, contributors, - writePath, - baseWritePath - }) + image: `https://img.youtube.com/vi/${youtubeCode}/mqdefault.jpg`, + featured: weight === 1, + weight, + youtubeCode + } + + const titleStripped = article.asciiDoc.replace(/== (.*)/, '') + const body = section.renderArticles || isTranslation ? asciidoctor.convert(titleStripped) : '' + + writeMarkdownFile(fileName, frontMatter, body) }) // Workbooks not translated. @@ -82,13 +93,18 @@ module.exports = async (writeDir, generatorFn, workbookFn, isJekyllSite) => { const contributors = await getContributors(`workbook/${section.workbook}`) const workbookPosition = articles.length + 1 - workbookFn({ - section, - workbookFileName, + const workbookFrontMatter = { + title: 'Workbook', contributors, - workbookPosition - }) + image: section.image, + weight: workbookPosition + } + + const workbookReadPath = join('..', 'workbook', section.workbook) + const body = asciidoctor.convert(fs.readFileSync(workbookReadPath, 'utf-8')) + + writeMarkdownFile(workbookFileName, workbookFrontMatter, body) } }) }) -} +})()