forked from stackbit/jamstackthemes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrub-themes.js
More file actions
42 lines (32 loc) · 1.23 KB
/
scrub-themes.js
File metadata and controls
42 lines (32 loc) · 1.23 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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const yamlFront = require('yaml-front-matter');
const gh = require('parse-github-url');
const isAfter = require('date-fns/isAfter')
const parseISO = require('date-fns/parseISO')
const themesFolder = './content/theme';
const themeFiles = fs.readdirSync(themesFolder);
const themesData = JSON.parse(fs.readFileSync('./data/themes.json'));
console.log("***********************************")
console.log("Scrubbing Themes")
console.log("***********************************")
const loadThemeData = file => {
const fileData = fs.readFileSync(path.join(themesFolder, file));
const frontmatter = yamlFront.loadFront(fileData);
if (frontmatter.disabled) {
return false
}
let repoUrl = frontmatter.github
let repoName = gh(frontmatter.github).repo;
let branch = frontmatter.github_branch ? frontmatter.github_branch : 'master';
let themeKey = repoName.replace("/", "-").toLowerCase() + "-" + branch;
const lastCommit = themesData[themeKey].last_commit
const stale = isAfter(parseISO(lastCommit), new Date(2018, 0, 1));
};
const getThemes = async () => {
for(const file of themeFiles) {
loadThemeData(file)
}
}
getThemes()