-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathsync-blog.mts
67 lines (57 loc) · 1.68 KB
/
sync-blog.mts
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
58
59
60
61
62
63
64
65
66
67
import gulp from "gulp";
import fs from "fs/promises";
import _ from "lodash";
import { getWorkspacePages } from "./services/blog/getWorkspacePages";
import { getTemplateWorkspacePages } from "./services/templates/getWorkspacePages";
import file from "gulp-file";
function cleanBlog() {
return fs.rm("./content/blog", { recursive: true, force: true });
}
function cleanTemplates() {
return fs.rm("./content/templates", { recursive: true, force: true });
}
async function convertBlogToMarkdowns() {
try {
const pages = ((await getWorkspacePages()) ?? []).filter(
(page) => page.publish
);
if (!pages || !pages.length) {
throw new Error("No pages");
}
_.uniqBy(pages, "slug").map((page, index) => {
return gulp
.src("/content/*")
.pipe(file(`${page.slug}.json`, JSON.stringify(page, null, 2)))
.pipe(gulp.dest("./content/blog"));
});
} catch (error) {
console.log("convertBlogToMarkdowns error", error);
throw error;
}
}
async function convertTemplatesToMarkdowns() {
try {
const pages = ((await getTemplateWorkspacePages()) ?? []).filter(
(page) => page.publish
);
if (!pages || !pages.length) {
throw new Error("No pages");
}
_.uniqBy(pages, "slug").map((page, index) => {
return gulp
.src("/content/*")
.pipe(file(`${page.slug}.json`, JSON.stringify(page, null, 2)))
.pipe(gulp.dest("./content/templates"));
});
} catch (error) {
console.log("convertTemplatesToMarkdowns error", error);
throw error;
}
}
async function main() {
await cleanBlog();
await cleanTemplates();
convertTemplatesToMarkdowns();
convertBlogToMarkdowns();
}
main();