-
Notifications
You must be signed in to change notification settings - Fork 47
New website scripts #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tsadler1988
merged 28 commits into
InnerSourceCommons:master
from
tsadler1988:new-website-scripts
Mar 2, 2021
Merged
New website scripts #369
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
87aa590
First pass at script for new website
tsadler1988 2a13696
Do not render Product Owner articles (as per current website)
tsadler1988 72c89f9
Remove translations and fix workbook for new site
tsadler1988 01461de
Fix typo
tsadler1988 59f68e7
Fix typo
tsadler1988 b2fbc10
Merge branch 'master' into new-website-scripts
tsadler1988 f9cbd3b
Refactor mkdirSync into a separate file
tsadler1988 14223ef
Refactor getArticleFiles into a separate file
tsadler1988 cb82aa8
Refactor writeMarkdownFile into a separate file
tsadler1988 680c64d
Refactor section data into a separate file
tsadler1988 0da6b05
Parameterise and share generator code for old and new site
tsadler1988 aaa4920
Tweaks to make old website output consistent with current output
tsadler1988 e332db8
Remove resolved TODOs
tsadler1988 013bd5c
Update docs following refactor
tsadler1988 3feef35
Get video specific thumbnails from YouTube
tsadler1988 9e5400b
Add docs around generating for new site
tsadler1988 72a3776
Strip title for new site
tsadler1988 989d594
Add isc.net urls
tsadler1988 bba404a
Add .node-version file - some scripts use node 12 features
tsadler1988 60f4929
Make scripts cross-platform friendly
tsadler1988 0b10074
Update README
tsadler1988 d7fec7a
New website translations
tsadler1988 1b76ec0
Update README with instructions for translations and links
tsadler1988 2e33f8f
Merge branch 'master' into new-website-scripts
rrrutledge cc19ada
Merge branch 'master' into new-website-scripts
tsadler1988 cae0708
Rename scripts to hugo/jekyll
tsadler1988 ba4513e
Update script link in origin statement
tsadler1988 9abac28
Merge branch 'new-website-scripts' of github.com:tsadler1988/InnerSou…
tsadler1988 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ | |
| \.DS_Store | ||
| scripts/node_modules | ||
| scripts/learningpath | ||
| scripts/newsite | ||
| scripts/.env | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 12 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // 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) | ||
| })() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| (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) | ||
| })() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,127 +1,57 @@ | ||
| (async() => { | ||
| const fs = require('fs') | ||
| const YAML = require('yaml') | ||
| const { EOL } = require('os') | ||
| const { join } = require('path') | ||
| const getContributors = require('./get_contributors') | ||
| const { join, basename, relative } = require('path') | ||
| const getContributors = require('./get_contributors') | ||
| const mkdirSync = require('./mkdir_sync') | ||
| const getArticleFiles = require('./get_article_files') | ||
|
|
||
| const mkdirSync = (dir) => { | ||
| try { | ||
| fs.mkdirSync(dir) | ||
| } catch (e) { | ||
| if (e.code !== 'EEXIST') { | ||
| console.log(e) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const getArticleFiles = (path) => { | ||
| return fs.readdirSync(path).reduce((articles, filename) => { | ||
| const filePath = `${path}/${filename}` | ||
| if (filePath.match(/\d\d/) && !filePath.includes('-script.asciidoc')) { | ||
| return [...articles, { | ||
| filePath, | ||
| asciiDoc: fs.readFileSync(filePath, 'utf-8') | ||
| }] | ||
| } else { | ||
| return articles | ||
| } | ||
| }, []) | ||
| } | ||
|
|
||
| const writeMarkdownFile = (filePath, frontMatter) => { | ||
| const frontMatterTerminator = '---' | ||
| const originStatement = '<!--- This file autogenerated from https://github.com/InnerSourceCommons/InnerSourceLearningPath/blob/master/scripts/generate_learning_path_markdown.js -->' | ||
| const output = [frontMatterTerminator, YAML.stringify(frontMatter).trim(), frontMatterTerminator, originStatement].join(EOL) | ||
| fs.writeFileSync(filePath, output) | ||
| } | ||
| const sections = require('./section_data.json') | ||
|
|
||
| const sections = [ | ||
| { | ||
| learning_path_group: 'Introduction', | ||
| dirName: 'introduction', | ||
| workbook: '01-introduction.asciidoc', | ||
| translations: ['de', 'it', 'ja', 'zh', 'ru'], | ||
| renderArticles: true | ||
| }, | ||
| { | ||
| learning_path_group: 'Trusted Committer', | ||
| dirName: 'trusted-committer', | ||
| workbook: '02-trusted-committer.asciidoc', | ||
| translations: ['de', 'zh'], | ||
| renderArticles: true | ||
| }, | ||
| { | ||
| learning_path_group: 'Contributor', | ||
| dirName: 'contributor', | ||
| workbook: '04-contributor.asciidoc', | ||
| translations: ['it', 'ja', 'zh'], | ||
| renderArticles: true | ||
| }, | ||
| { | ||
| learning_path_group: 'Product Owner', | ||
| dirName: 'product-owner', | ||
| workbook: '03-product-owner.asciidoc', | ||
| translations: ['zh'], | ||
| renderArticles: true | ||
| }, | ||
| ] | ||
| module.exports = async (writeDir, generatorFn, workbookFn, createTranslationFolder) => { | ||
| mkdirSync(join('.', writeDir)) | ||
|
|
||
| mkdirSync('./learningpath') | ||
|
|
||
| sections.forEach(({ learning_path_group, dirName, workbook, translations, renderArticles }) => { | ||
| const baseReadPath = `../${dirName}` | ||
| const baseWritePath = `./learningpath/${dirName}` | ||
| sections.forEach(section => { | ||
| const { dirName, translations } = section | ||
| const baseReadPath = join('..', dirName) | ||
| const baseWritePath = join('.', writeDir, dirName) | ||
| mkdirSync(baseWritePath) | ||
|
|
||
| translations.concat('' /* The English original */).forEach(async (translation) => { | ||
| const isTranslation = translation !== '' | ||
| const writePath = join(baseWritePath, translation) | ||
| mkdirSync(writePath) | ||
| if (createTranslationFolder) mkdirSync(writePath) | ||
rrrutledge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const readPath = join(baseReadPath, translation) | ||
| const articles = getArticleFiles(readPath) | ||
| articles.forEach(async (article) => { | ||
| const articleTitle = article.asciiDoc.match(/== (.*)/)[1] | ||
| const articleNumber = article.filePath.split('/').pop().split('-')[0] | ||
| const fileName = articleNumber === '01' ? `${writePath}/index.md` : `${writePath}/${articleNumber}.md` | ||
| const contributors = await getContributors(article.filePath.replace('../', '')) | ||
| const frontMatter = { | ||
| layout: 'learning-path-page', | ||
| show_meta: false, | ||
| title: `Learning Path - ${learning_path_group} - ${articleTitle}`, | ||
| learning_path_article: renderArticles ? article.filePath.replace('../', '') : undefined, | ||
| 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 articleNumber = basename(article.filePath).split('-')[0] | ||
| const contributors = await getContributors(relative('..', article.filePath)) | ||
|
|
||
| generatorFn({ | ||
| section, | ||
| articleTitle, | ||
| articleNumber, | ||
| isTranslation, | ||
| article, | ||
| translation, | ||
| contributors, | ||
| writePath, | ||
| baseWritePath | ||
| }) | ||
| }) | ||
|
|
||
| // Workbooks not translated. | ||
| if (!isTranslation) { | ||
| const workbookFileName = `${writePath}/workbook.md` | ||
| const contributors = await getContributors(`workbook/${workbook}`) | ||
| console.log('workbookFileName', workbookFileName) | ||
| const workbookFrontMatter = { | ||
| layout: 'learning-path-page', | ||
| show_meta: false, | ||
| title: `Learning Path - ${learning_path_group} - Workbook`, | ||
| learning_path_article: `workbook/${workbook}`, | ||
| learning_path_group, | ||
| learning_path_menu_title: `${learning_path_group} Workbook`, | ||
| learning_path_position: articles.length - articles.filter(Array.isArray).length + 1, | ||
| learning_path_translation: translation, | ||
| no_video: true, | ||
| contributors | ||
| } | ||
|
|
||
| writeMarkdownFile(workbookFileName, workbookFrontMatter) | ||
| const workbookFileName = join(baseWritePath, 'workbook.md') | ||
| const contributors = await getContributors(`workbook/${section.workbook}`) | ||
| const workbookPosition = articles.length + 1 | ||
|
|
||
| workbookFn({ | ||
| section, | ||
| workbookFileName, | ||
| contributors, | ||
| workbookPosition | ||
| }) | ||
| } | ||
| }) | ||
| }) | ||
| })() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| const fs = require('fs') | ||
| const { join } = require('path') | ||
|
|
||
| module.exports = getArticleFiles = (path) => { | ||
| return fs.readdirSync(path).reduce((articles, filename) => { | ||
| const filePath = join(path, filename) | ||
| if (filePath.match(/\d\d/) && !filePath.includes('-script.asciidoc')) { | ||
| return [...articles, { | ||
| filePath, | ||
| asciiDoc: fs.readFileSync(filePath, 'utf-8') | ||
| }] | ||
| } else { | ||
| return articles | ||
| } | ||
| }, []) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| const fs = require('fs') | ||
|
|
||
| module.exports = mkdirSync = (dir) => { | ||
| try { | ||
| fs.mkdirSync(dir) | ||
| } catch (e) { | ||
| if (e.code !== 'EEXIST') { | ||
| console.log(e) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.