Skip to content

Commit

Permalink
feat(11ty): Add the foundations of the new 11ty architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanBt authored and ffoodd committed Mar 3, 2022
1 parent 0e50693 commit c334fc4
Show file tree
Hide file tree
Showing 26 changed files with 11,774 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const a11yCSS = require('./a11y.css')

module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(a11yCSS)

eleventyConfig.addPassthroughCopy('src/assets')

return {
dir: {
input: 'src'
},
markdownTemplateEngine: 'njk'
}
}
1 change: 1 addition & 0 deletions .eleventyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/src/assets/*.html
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ node_modules
prepros.cfg
/docs/Hologram/tests
/docs/SassDoc/*
_site/
src/_data/sass
*.log
.vscode
.DS_Store
Expand Down
65 changes: 65 additions & 0 deletions a11y.css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const fs = require('fs')
const path = require('path')
const showdown = require('showdown')
const fm = require('front-matter')

const INPUT_DIRECTORY = './sass/themes/'
const OUTPUT_DIRECTORY = './src/_data/sass/'

const processSassDocumentation = (file) => {
const inputFileExtension = path.extname(file)
const inputFilename = path.basename(file, inputFileExtension)
const excludeFiles = ['_all']

// Exclude files that we don't want to process
if (inputFileExtension !== '.scss' || excludeFiles.includes(inputFilename)) {
return
}

const content = fs.readFileSync(file, 'utf8')
const commentBlockRegex = /\/\*doc(.)*?\*\//gs

const comments = Array.from(content.matchAll(commentBlockRegex), data => {
return parseSassComment(data[0])
})

// Avoid crash if output directory does not exists
if (!fs.existsSync(OUTPUT_DIRECTORY)) {
fs.mkdirSync(OUTPUT_DIRECTORY)
}

// Write Eleventy data files
fs.writeFileSync(
`${OUTPUT_DIRECTORY}/${inputFilename.replace('_', '')}.json`,
JSON.stringify(comments, null, 2)
)
}

const parseSassComment = comment => {
// Remove CSS comments syntax
comment = comment.replace(/(\/\*doc|\*\/)/g, '').trim()

const content = fm(comment)

return {
attributes: content.attributes,
body: new showdown.Converter().makeHtml(content.body)
}
}

const generateJsonDocumentation = () => {
/**
* Remove output directory before creating it again
* @note This is an experimental feature and requires Node v12.10.0 at least
* @see https://nodejs.org/api/fs.html#fs_fs_rmdirsync_path_options
*/
fs.rmdirSync(OUTPUT_DIRECTORY, { recursive: true })

fs.readdirSync(INPUT_DIRECTORY).forEach(file => {
processSassDocumentation(INPUT_DIRECTORY + file)
})
}

module.exports = function () {
generateJsonDocumentation()
}
Loading

0 comments on commit c334fc4

Please sign in to comment.