Skip to content
Merged
Show file tree
Hide file tree
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 Feb 4, 2021
2a13696
Do not render Product Owner articles (as per current website)
tsadler1988 Feb 4, 2021
72c89f9
Remove translations and fix workbook for new site
tsadler1988 Feb 4, 2021
01461de
Fix typo
tsadler1988 Feb 4, 2021
59f68e7
Fix typo
tsadler1988 Feb 4, 2021
b2fbc10
Merge branch 'master' into new-website-scripts
tsadler1988 Feb 19, 2021
f9cbd3b
Refactor mkdirSync into a separate file
tsadler1988 Feb 19, 2021
14223ef
Refactor getArticleFiles into a separate file
tsadler1988 Feb 19, 2021
cb82aa8
Refactor writeMarkdownFile into a separate file
tsadler1988 Feb 19, 2021
680c64d
Refactor section data into a separate file
tsadler1988 Feb 19, 2021
0da6b05
Parameterise and share generator code for old and new site
tsadler1988 Feb 19, 2021
aaa4920
Tweaks to make old website output consistent with current output
tsadler1988 Feb 19, 2021
e332db8
Remove resolved TODOs
tsadler1988 Feb 19, 2021
013bd5c
Update docs following refactor
tsadler1988 Feb 19, 2021
3feef35
Get video specific thumbnails from YouTube
tsadler1988 Feb 19, 2021
9e5400b
Add docs around generating for new site
tsadler1988 Feb 19, 2021
72a3776
Strip title for new site
tsadler1988 Feb 19, 2021
989d594
Add isc.net urls
tsadler1988 Feb 19, 2021
bba404a
Add .node-version file - some scripts use node 12 features
tsadler1988 Feb 19, 2021
60f4929
Make scripts cross-platform friendly
tsadler1988 Feb 19, 2021
0b10074
Update README
tsadler1988 Feb 19, 2021
d7fec7a
New website translations
tsadler1988 Feb 20, 2021
1b76ec0
Update README with instructions for translations and links
tsadler1988 Feb 20, 2021
2e33f8f
Merge branch 'master' into new-website-scripts
rrrutledge Feb 26, 2021
cc19ada
Merge branch 'master' into new-website-scripts
tsadler1988 Feb 27, 2021
cae0708
Rename scripts to hugo/jekyll
tsadler1988 Feb 27, 2021
ba4513e
Update script link in origin statement
tsadler1988 Feb 27, 2021
9abac28
Merge branch 'new-website-scripts' of github.com:tsadler1988/InnerSou…
tsadler1988 Feb 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
\.DS_Store
scripts/node_modules
scripts/learningpath
scripts/newsite
scripts/.env
54 changes: 54 additions & 0 deletions config/urls.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions scripts/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12
33 changes: 26 additions & 7 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ For example, to point all links to innersourcecommons.org:
node substitute_article_urls.js isc
```

## generate_learning_path_markdown.js
## generate_jekyll_learning_path_markdown.js, generate_hugo_learning_path_markdown.js

A node script to generate markdown files required for hosting Learning Path on innersourcecommons.org.
Node scripts to generate markdown files required for hosting Learning Path on innersourcecommons.org and innersourcecommons.net.

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:
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:
```
TOKEN=<your_github_token>
```

### Usage:
```
npm ci
node generate_learning_path_markdown.js
node generate_jekyll_learning_path_markdown.js
node generate_hugo_learning_path_markdown.js
```

## How to update innersourcecommons.org with new articles
Expand All @@ -38,17 +39,35 @@ Anytime there are _new_ articles written, you need to run the script that genera
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/generate_learning_path_markdown.js#L37) with the language code of the articles for the appropriate section.
* 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_learning_path_markdown.js** as described above.
3. Run **generate_jekyll_learning_path_markdown.js** as described above.
3. `cp -r learningpath/* <path-to-innersourcecommons.org-repo>/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.

[innersourcecommons.org]: http://www.innersourcecommons.org/
## 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/ <path-to-innersourcecommons.net-repo>/content/learn/learning-path/`.
3. Open a pull request with the modified files in the [InnerSourceCommons/innersourcecommons.net] 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
55 changes: 55 additions & 0 deletions scripts/generate_hugo_learning_path_markdown.js
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)
})()
43 changes: 43 additions & 0 deletions scripts/generate_jekyll_learning_path_markdown.js
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)
})()
144 changes: 37 additions & 107 deletions scripts/generate_learning_path_markdown.js
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)

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
})
}
})
})
})()
}
16 changes: 16 additions & 0 deletions scripts/get_article_files.js
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
}
}, [])
}
11 changes: 11 additions & 0 deletions scripts/mkdir_sync.js
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)
}
}
}
Loading