Browse Source

Parse.js now automatically updates the date of index.html

pull/105/head
Jure Šorn 3 years ago
parent
commit
1fa9a9939b
3 changed files with 26 additions and 8 deletions
  1. 6
      index.html
  2. 26
      parse.js
  3. 2
      web/template.html

6
index.html

@ -226,7 +226,7 @@ pre.prettyprint {
<body> <body>
<header> <header>
<aside>May 20, 2021</aside>
<aside>August 11, 2021</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a> <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header> </header>
@ -3005,8 +3005,8 @@ $ pyinstaller script.py --add-data '&lt;path&gt;:.' <span class="hljs-comment">
<footer> <footer>
<aside>May 20, 2021</aside>
<a href="../" rel="author">Jure Šorn</a>
<aside>August 11, 2021</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer> </footer>
<script src="web/jquery-3.4.0.min.js"></script> <script src="web/jquery-3.4.0.min.js"></script>

26
parse.js

@ -2,20 +2,25 @@
// Usage: node parse.js // Usage: node parse.js
// //
// Script that creates index.html out of web/template.html and README.md. // Script that creates index.html out of web/template.html and README.md.
//
// It is written in JS because this code used to be executed on the client side. // It is written in JS because this code used to be executed on the client side.
// To install the Node.js and npm run: // To install the Node.js and npm run:
// $ sudo apt install nodejs npm # On macOS use `brew install ...` instead. // $ sudo apt install nodejs npm # On macOS use `brew install ...` instead.
//
// To install dependencies globally, run: // To install dependencies globally, run:
// $ npm install -g jsdom jquery showdown highlightjs@9.12.0 // $ npm install -g jsdom jquery showdown highlightjs@9.12.0
//
// If running on macOS and modules can't be found after installation add: // If running on macOS and modules can't be found after installation add:
// export NODE_PATH=/usr/local/lib/node_modules // export NODE_PATH=/usr/local/lib/node_modules
// to the ~/.bash_profile or ~/.bashrc file and run '$ bash'. // to the ~/.bash_profile or ~/.bashrc file and run '$ bash'.
//
// To avoid problems with permissions and path variables, install modules // To avoid problems with permissions and path variables, install modules
// into project's directory using: // into project's directory using:
// $ npm install jsdom jquery showdown highlightjs@9.12.0 // $ npm install jsdom jquery showdown highlightjs@9.12.0
// It is also advisable to add a script into .git/hooks directory, that will run
// this script before every commit. It should be named 'pre-commit' and it should
// contain the following line: `./parse.js`.
//
// It is also advisable to add a Bash script into .git/hooks directory, that will
// run this script before every commit. It should be named 'pre-commit' and it
// should contain the following line: `./parse.js`.
const fs = require('fs'); const fs = require('fs');
@ -408,7 +413,8 @@ function main() {
const html = getMd(); const html = getMd();
initDom(html); initDom(html);
modifyPage(); modifyPage();
const template = readFile('web/template.html');
var template = readFile('web/template.html');
template = updateDate(template);
const tokens = template.split('<div id=main_container></div>'); const tokens = template.split('<div id=main_container></div>');
const text = `${tokens[0]} ${document.body.innerHTML} ${tokens[1]}`; const text = `${tokens[0]} ${document.body.innerHTML} ${tokens[1]}`;
writeToFile('index.html', text); writeToFile('index.html', text);
@ -580,6 +586,18 @@ function removePlotImages() {
$('img[alt="Covid Cases"]').remove(); $('img[alt="Covid Cases"]').remove();
} }
function updateDate(template) {
const date = new Date();
const date_str = date.toLocaleString('en-us', {month: 'long', day: 'numeric', year: 'numeric'});
template = template.replace('May 20, 2021', date_str);
template = template.replace('May 20, 2021', date_str);
return template;
}
// UTIL
function readFile(filename) { function readFile(filename) {
try { try {
return fs.readFileSync(filename, 'utf8'); return fs.readFileSync(filename, 'utf8');

2
web/template.html

@ -235,7 +235,7 @@ pre.prettyprint {
<footer> <footer>
<aside>May 20, 2021</aside> <aside>May 20, 2021</aside>
<a href="../" rel="author">Jure Šorn</a>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer> </footer>
<script src="web/jquery-3.4.0.min.js"></script> <script src="web/jquery-3.4.0.min.js"></script>

Loading…
Cancel
Save