forked from profmancusoa/profmancusoa.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.js
More file actions
57 lines (46 loc) · 1.14 KB
/
Copy patharticle.js
File metadata and controls
57 lines (46 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Console } from 'node:console';
import * as fs from 'node:fs/promises';
import { exit } from 'node:process';
const POST_DIR = './src/routes/blog/';
const IMG_DIR = './static/img/posts/';
let FRONT_MATTER = `
---
id: {data}-1
titolo: {titolo}
featured: false
autore: <autore>
data: {data}
cover:
introduzione: <introduzione>
pubblicato: false
sezione: <sezione>
categorie:
- <categoria1>
- <categoria2>
---
# {titolo}
`;
const titolo2slug = (titolo) => {
return titolo.toLowerCase().split(' ').join('-');
};
const fill_fornt_matter = (titolo) => {
FRONT_MATTER = FRONT_MATTER.replaceAll(
'{data}',
new Date().toISOString().split('T')[0]
).replaceAll('{titolo}', titolo);
return FRONT_MATTER;
};
(async function () {
console.clear();
if (process.argv.length != 3) {
console.log('Usage: article.js <titolo> \n');
exit();
}
let titolo = process.argv[2];
let slug = titolo2slug(titolo);
//creo il file .md per il post
fs.writeFile(POST_DIR + slug + '.md', fill_fornt_matter(titolo));
//creo la directory per le immagini del post
fs.mkdir(IMG_DIR + slug);
console.log(`Articolo "${titolo}" creato con successo!!`);
})();