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
parent
39d6149a01
commit
3d5b5da7ad
|
@ -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();
|
||||
}
|
|
@ -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",
|
||||
|
|
43
pages.js
43
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();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
.home {
|
||||
margin-left: 1em;
|
||||
}
|
|
@ -94,3 +94,6 @@ $fa-font-path: "../webfonts";
|
|||
@import "layout/main";
|
||||
@import "layout/footer";
|
||||
@import "layout/wrapper";
|
||||
|
||||
// BirbMC
|
||||
@import "birbmc";
|
||||
|
|
|
@ -221,12 +221,26 @@
|
|||
<p class="content">
|
||||
Join our
|
||||
<a href="https://steamcommunity.com/groups/BirbMC"
|
||||
>Steam Group</a
|
||||
>Steam Group</a
|
||||
>
|
||||
</p>
|
||||
</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>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"community": {
|
||||
"Grand River's YouTube": "https://www.youtube.com/c/GrandRiverGaming"
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue