diff --git a/index.js b/index.js new file mode 100644 index 0000000..e6431d8 --- /dev/null +++ b/index.js @@ -0,0 +1,50 @@ +const fs = require('fs'); +const pages = require('./pages'); + +// Index +const srcIndex = 'src/index.html'; +const srcIndexConfig = 'src/index.json'; +// Where to put it +const distIndex = 'dist/index.html' + +// Actual processing +function run() { + const config = indexConfig(); + + // Community + const community = []; + const configCommunity = config['community']; + Object.keys(configCommunity).forEach((c) => { + community.push(`
  • ${c}

  • `); + }); + + // Pages + const other = []; + pages.getPages().forEach((page) => { + other.push(`
  • ${page.title}

  • `); + }); + + fs.writeFileSync(distIndex, buildIndex(community, other)) +} + +const indexTemplate = fs.readFileSync(srcIndex).toString(); + +// Inject the config +function buildIndex(community, pages) { + return indexTemplate + .replace('{{community}}', community) + .replace('{{pages}}', pages) +} + +// Module stuff +function indexConfig() { + const contents = fs.readFileSync(srcIndexConfig); + return JSON.parse(contents.toString()); +} + +module.exports = { indexConfig }; + +// Run the h*ckin' thing +if (require.main === module) { + run(); +} diff --git a/package.json b/package.json index 1fc1fe4..78b02b7 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,10 @@ "sass-noscript": "npx dart-sass -s compressed src/assets/sass/noscript.scss src/assets/css/noscript.css", "sass": "npm run sass-main && npm run sass-noscript", "webfonts": "npx copyfiles --flat node_modules/@fortawesome/fontawesome-free/webfonts/* src/assets/webfonts/", - "dist": "npx copyfiles --exclude src/elements.html --exclude src/generic.html --exclude src/pages.html --up 1 src/* src/assets/css/* src/assets/js/* src/assets/webfonts/* src/images/* dist/", + "dist": "npx copyfiles --up 1 src/assets/css/* src/assets/js/* src/assets/webfonts/* src/images/* dist/", "pages": "node pages.js", - "build": "npm run webfonts && npm run sass && npm run dist && npm run pages" + "index": "node index.js", + "build": "npm run webfonts && npm run sass && npm run dist && npm run pages && npm run index" }, "repository": { "type": "git", diff --git a/pages.js b/pages.js index c2a3302..74e77d2 100644 --- a/pages.js +++ b/pages.js @@ -14,16 +14,10 @@ const requiredMeta = ['title'] // Actual processing function run() { if (!fs.existsSync(distDir)) fs.mkdirSync(distDir); - fs.readdirSync(dir).forEach((file) => { - const filePath = path.join(dir, file) - const contents = fs.readFileSync(filePath); - const meta = frontmatter(contents.toString()) - const errs = validateMeta(meta); - if (errs.length) throw `Errors in ${file}:\n${errs.join('\n')}`; - const dirPath = path.join(distDir, 'path' in meta.attributes ? meta.attributes.path : path.basename(file, '.md')); + getPages().forEach((page) => { + const dirPath = path.join(distDir, page.path); if (!fs.existsSync(dirPath)) fs.mkdirSync(dirPath); - const body = converter.makeHtml(meta.body); - fs.writeFileSync(path.join(dirPath, 'index.html'), buildTemplate(meta.attributes.title, body)) + fs.writeFileSync(path.join(dirPath, 'index.html'), buildTemplate(page.title, page.body)) }); } @@ -48,5 +42,34 @@ function validateMeta(meta) { return errs } + +// Module stuff +class Page { + constructor(title, path, body, file) { + this.title = title; + this.path = path; + this.body = body; + this.file = file; + } +} + +function getPages() { + const pages = []; + fs.readdirSync(dir).forEach((file) => { + const filePath = path.join(dir, file) + const contents = fs.readFileSync(filePath); + const meta = frontmatter(contents.toString()) + const errs = validateMeta(meta); + if (errs.length) throw `Errors in ${file}:\n${errs.join('\n')}`; + const body = converter.makeHtml(meta.body); + pages.push(new Page(meta.attributes.title, 'path' in meta.attributes ? meta.attributes.path : path.basename(file), body, file)); + }); + return pages; +} + +module.exports = { getPages }; + // Run the h*ckin' thing -run(); +if (require.main === module) { + run(); +} diff --git a/src/assets/sass/_birbmc.scss b/src/assets/sass/_birbmc.scss new file mode 100644 index 0000000..d1792ba --- /dev/null +++ b/src/assets/sass/_birbmc.scss @@ -0,0 +1,3 @@ +.home { + margin-left: 1em; +} diff --git a/src/assets/sass/main.scss b/src/assets/sass/main.scss index 132628f..68725bd 100644 --- a/src/assets/sass/main.scss +++ b/src/assets/sass/main.scss @@ -94,3 +94,6 @@ $fa-font-path: "../webfonts"; @import "layout/main"; @import "layout/footer"; @import "layout/wrapper"; + +// BirbMC +@import "birbmc"; diff --git a/src/index.html b/src/index.html index 5902ef1..34a85a5 100644 --- a/src/index.html +++ b/src/index.html @@ -221,12 +221,26 @@

    Join our Steam GroupSteam Group

    + +
    +

    Community Spotlight

    + +
    + +
    +

    Other Pages

    + +

    Donations

    diff --git a/src/index.json b/src/index.json new file mode 100644 index 0000000..b885966 --- /dev/null +++ b/src/index.json @@ -0,0 +1,5 @@ +{ + "community": { + "Grand River's YouTube": "https://www.youtube.com/c/GrandRiverGaming" + } +} diff --git a/src/pages.html b/src/pages.html index f516add..7f14562 100644 --- a/src/pages.html +++ b/src/pages.html @@ -27,6 +27,7 @@
    +
    Home
    {{body}}