Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use projects.yaml in build process, not hard-coded #6

Merged
merged 4 commits into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
index.js
build/*
3 changes: 1 addition & 2 deletions .linthtmlrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"tag-close": true,
"tag-name-lowercase": true,
"tag-name-match": true,
"doctype-first": true,
"doctype-html5": true,
"attr-name-style": "dash",
"attr-quote-style": "double",
Expand All @@ -16,7 +15,7 @@
"id-class-no-ad": false,
"id-class-style": "dash",
"class-no-dup": true,
"class-style": "dash",
"class-style": none,
"img-req-alt": true,
"img-req-src": true,
"html-valid-content-model": true,
Expand Down
395 changes: 0 additions & 395 deletions index.html

This file was deleted.

49 changes: 44 additions & 5 deletions js/projects.js → index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
* <https://github.com/MattIPv4/Personal-Site/blob/master/LICENSE.md> or <http://www.gnu.org/licenses/>.
*/

/* eslint-disable-next-line no-unused-vars */
var toolMap = {
const { readFileSync, writeFileSync } = require('fs');
const { parse } = require('yaml');
const md = require('markdown-it')();

// Define all the icons for the tools
const toolMap = {
'phpstorm': 'devicon-phpstorm-plain',
'webstorm': 'devicon-webstorm-plain',
'pycharm': 'devicon-pycharm-plain',
Expand Down Expand Up @@ -63,6 +67,41 @@ var toolMap = {
'slack': 'fab fa-slack'
};

// TODO: 1. Fetch projects.yaml
// TODO: 2. Parse YAML
// TODO: 3. Generate projects HTML
// Get the projects in a usable data format
const yaml = parse(readFileSync('projects.yaml', 'utf8'));
const projects = Object.keys(yaml).map(key => {
// Name
const data = yaml[key];
data.name = key;

// Icons
data.icons = data.tools.map(tool => {
const key = tool.toString().toLowerCase();
if (!(key in toolMap)) return tool;
return {
classes: toolMap[key],
name: tool
};
});

// Markdown
data.desc = md.renderInline(data.desc).replace(/<a (.+?)>/g, '<a $1 target="_blank" rel="noopener">');

return data;
}).filter(x => x.display);

// Load all the PostHTML requirements
const posthtml = require('posthtml');
const expressions = require('posthtml-expressions');
const include = require('posthtml-include');

// Get the source html
const html = readFileSync('templates/index.html', 'utf8');

// Render it
posthtml([
include({ encoding: 'utf8' }),
expressions({ locals: { projects } }),
])
.process(html)
.then((result) => writeFileSync('build/index.html', result.html, { flag: 'w+' }));
95 changes: 95 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
"name": "personal-site",
"version": "1.0.0",
"description": "My humble personal homepage, made with a tiny bit but not much care.",
"main": "index.html",
"main": "index.js",
"scripts": {
"lint": "npm run lint:js && npm run lint:scss && npm run lint:html",
"lint:js": "eslint js/*.js",
"lint:js:fix": "eslint js/*.js --fix",
"lint:js": "eslint *.js",
"lint:js:fix": "eslint *.js --fix",
"lint:scss": "sass-lint scss/{*,**/*}.scss --verbose --no-exit --config .sasslintrc",
"lint:html": "linthtml *.html",
"lint:html": "linthtml templates/*.html",
"build": "npm run build:scss && npm run build:js && npm run build:html && npm run build:static",
"build:scss": "parcel build scss/*.scss --out-dir build/css --public-url ./",
"build:js": "parcel build js/*.js --out-dir build/js --public-url ./",
"build:html": "html-minifier index.html -c .htmlminrc -o build/index.html",
"build:html": "npm run build:html:posthtml && npm run build:html:minify",
"build:html:posthtml": "node index.js",
"build:html:minify": "html-minifier build/index.html -c .htmlminrc -o build/index.html",
"build:static": "copyfiles --up 1 static/{*,**/*} build"
},
"repository": {
Expand All @@ -30,8 +32,13 @@
"copyfiles": "^2.1.1",
"eslint": "^6.3.0",
"html-minifier": "^4.0.0",
"markdown-it": "^9.1.0",
"parcel-bundler": "^1.12.3",
"posthtml": "^0.11.6",
"posthtml-expressions": "^1.1.1",
"posthtml-include": "^1.2.0",
"sass": "^1.23.0-module.beta.1",
"sass-lint": "^1.13.1"
"sass-lint": "^1.13.1",
"yaml": "^1.6.0"
}
}
Loading