spotlight (#2)

Merge branch 'main' of https://git.birbmc.com/BirbMC/birbmc.com into spotlight

# Conflicts:
#	package.json
#	pages.js
#	src/pages.html

Add community spotlight and inject extra pages.

Signed-off-by: Etzelia <etzelia@hotmail.com>

Add pages (#16)

Execute anonymous function

Signed-off-by: Etzelia <etzelia@hotmail.com>

Exclude pages.html, it's only used as a template

Signed-off-by: Etzelia <etzelia@hotmail.com>

Add pages

Signed-off-by: Etzelia <etzelia@hotmail.com>

Co-authored-by: Etzelia <etzelia@hotmail.com>
Reviewed-on: https://git.etztech.xyz/BirbMC/birbmc.com/pulls/16
Reviewed-by: ZeroHD <joey@ahines.net>
Co-Authored-By: Etzelia <etzelia@noreply.example.org>
Co-Committed-By: Etzelia <etzelia@noreply.example.org>

Co-authored-by: Etzelia <etzelia@noreply.example.org>
Reviewed-on: https://git.birbmc.com/BirbMC/birbmc.com/pulls/2
Co-Authored-By: Etzelia <etzelia@hotmail.com>
Co-Committed-By: Etzelia <etzelia@hotmail.com>
pull/1/head
Etzelia 2021-05-18 13:49:52 +00:00
parent 39d6149a01
commit 3d5b5da7ad
8 changed files with 113 additions and 13 deletions

50
index.js 100644
View File

@ -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(`<li><p class="content"><a href="${configCommunity[c]}">${c}</a></p></li>`);
});
// Pages
const other = [];
pages.getPages().forEach((page) => {
other.push(`<li><p class="content"><a href="${page.path}">${page.title}</a></p></li>`);
});
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();
}

View File

@ -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",

View File

@ -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
if (require.main === module) {
run();
}

View File

@ -0,0 +1,3 @@
.home {
margin-left: 1em;
}

View File

@ -94,3 +94,6 @@ $fa-font-path: "../webfonts";
@import "layout/main";
@import "layout/footer";
@import "layout/wrapper";
// BirbMC
@import "birbmc";

View File

@ -227,6 +227,20 @@
</li>
</ul>
</div>
<div style="break-inside: avoid">
<h3>Community Spotlight</h3>
<ul class="content">
{{community}}
</ul>
</div>
<div style="break-inside: avoid">
<h3>Other Pages</h3>
<ul class="content">
{{pages}}
</ul>
</div>
</section>
<h3>Donations</h3>

5
src/index.json 100644
View File

@ -0,0 +1,5 @@
{
"community": {
"Grand River's YouTube": "https://www.youtube.com/c/GrandRiverGaming"
}
}

View File

@ -27,6 +27,7 @@
<!-- Main -->
<div id="main">
<div class="home"><a href="../"><span class="icon solid style4 fa-home"></span> Home</a></div>
<section id="second" class="main">
{{body}}
</section>