-
Notifications
You must be signed in to change notification settings - Fork 15
Collapse file tree
Files
Search this repository
/
Copy path_cms.ts
More file actions
More file actions
89 lines (82 loc) · 2.29 KB
/
_cms.ts
File metadata and controls
89 lines (82 loc) · 2.29 KB
You must be signed in to make or propose changes
More edit options
Edit and raw actions
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { privateRepoStorage } from "./_storage.ts";
import lumeCMS from "lume/cms/mod.ts";
import type Site from "lume/core/site.ts";
import type { CMSContent } from "lume/cms/types.ts";
const cms = lumeCMS({
site: {
name: "デジタル民主主義2030",
description: "デジタル民主主義2030プロジェクトポータルサイトのCMS",
url: "https://dd2030.org",
body: `
<p>ここで「お知らせ」のコンテンツを編集できます。 draft は private repository へ保存されます。</p>
`,
},
});
const cmsPassword = Deno.env.get("CMS_PASSWORD");
if (!cmsPassword) {
throw new Error("CMS_PASSWORD is not set in environment variables");
}
cms.auth({ dd2030: cmsPassword });
cms.storage("gh", privateRepoStorage);
function dateToZoned(dateStr?: string | Date) {
if (typeof dateStr === "string") {
return Temporal.PlainDate.from(dateStr).toZonedDateTime("Asia/Tokyo");
} else if (dateStr instanceof Date || dateStr === undefined) {
return (dateStr || new Date()).toTemporalInstant().toZonedDateTimeISO(
"Asia/Tokyo",
);
}
throw new Error("Invalid date");
}
cms.collection({
name: "topics_posts",
store: "gh:topics/*.md",
previewUrl: (path: string, cms: CMSContent, hasChanged: boolean) => {
const site: Site = cms.data.site;
const outputPath = path.replace(/\.md$/, ".html");
const srcPath = "/topics/drafts.page.ts";
if (hasChanged) {
site.update(new Set([srcPath]));
}
return site.url(outputPath);
},
documentName: (data) => {
return `${data.publish_on}-${data.title}.md`;
},
fields: [
{
name: "status",
type: "select",
options: [
{ label: "下書き", value: "draft" },
{ label: "URL公開", value: "unlisted" },
{ label: "公開", value: "" },
],
},
{
name: "tags",
type: "list",
},
{
name: "title",
type: "text",
value: `${dateToZoned().toPlainDate()}のお知らせ`,
},
{
name: "publish_on",
type: "date",
value: dateToZoned().toPlainDate().toString(),
},
{
name: "description",
type: "text",
},
{
name: "content",
type: "markdown",
upload: "topics_files",
},
],
});
cms.upload("topics_files", "gh:topics/files");
export default cms;