Skip to content

Commit dd40999

Browse files
committed
chore: replace timeFormat with new syntax time_format
1 parent 2177ae3 commit dd40999

File tree

2 files changed

+172
-104
lines changed

2 files changed

+172
-104
lines changed

site/static/admin/config.yml

Lines changed: 116 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ backend:
1616
# name: git-gateway
1717
# branch: main
1818

19-
20-
2119
media_folder: "site/static/img" # Folder where user uploaded files should go
2220
public_folder: "img"
2321

@@ -29,55 +27,97 @@ collections: # A list of collections the CMS should be able to edit
2927
path: "{{slug}}/index" # Each document is inside a folder with the slug name.
3028
create: true # Allow users to create new documents in this collection
3129
fields: # The fields each document in this collection have
32-
- {label: "Title", name: "title", widget: "string"}
33-
- {label: "Author", name: "author", widget: "string"}
34-
- {label: "Publish Date", name: "date", widget: "datetime", format: "YYYY-MM-DD", timeFormat: false}
35-
- {label: "Expiry Date", name: "expirydate", widget: "datetime", format: "YYYY-MM-DD", timeFormat: false, required: false, default: ''}
36-
- {label: "Body", name: "body", widget: "markdown"}
37-
- {label: "Draft", name: "draft", widget: "boolean", default: true}
38-
- {label: "Tags", name: "tipstags", widget: "list"}
30+
- { label: "Title", name: "title", widget: "string" }
31+
- { label: "Author", name: "author", widget: "string" }
32+
- {
33+
label: "Publish Date",
34+
name: "date",
35+
widget: "datetime",
36+
format: "YYYY-MM-DD",
37+
time_format: false,
38+
}
39+
- {
40+
label: "Expiry Date",
41+
name: "expirydate",
42+
widget: "datetime",
43+
format: "YYYY-MM-DD",
44+
time_format: false,
45+
required: false,
46+
default: "",
47+
}
48+
- { label: "Body", name: "body", widget: "markdown" }
49+
- { label: "Draft", name: "draft", widget: "boolean", default: true }
50+
- { label: "Tags", name: "tipstags", widget: "list" }
3951
- name: "post" # Used in routes, ie.: /admin/collections/:slug/edit
4052
label: "Post" # Used in the UI, ie.: "New Post"
4153
folder: "site/content/blog" # The path to the folder where the documents are stored
4254
media_folder: "."
4355
path: "{{slug}}/index" # Each document is inside a folder with the slug name.
4456
create: true # Allow users to create new documents in this collection
4557
fields: # The fields each document in this collection have
46-
- {label: "Title", name: "title", widget: "string"}
47-
- {label: "Author", name: "author", widget: "string"}
48-
- {label: "Url", name: "url", widget: "string"}
49-
- {label: "Aliases", name: "aliases", widget: "string"}
50-
- {label: "Publish Date", name: "date", widget: "datetime", format: "YYYY-MM-DD", timeFormat: false}
51-
- {label: "Expiry Date", name: "expirydate", widget: "datetime", format: "YYYY-MM-DD", timeFormat: false, required: false, default: ''}
52-
- {label: "Image", name: "cover", widget: "image", required: false}
53-
- {label: "Body", name: "body", widget: "markdown"}
54-
- {label: "Draft", name: "draft", widget: "boolean", default: true}
55-
- {label: "Tags", name: "tags", widget: "list"}
58+
- { label: "Title", name: "title", widget: "string" }
59+
- { label: "Author", name: "author", widget: "string" }
60+
- { label: "Url", name: "url", widget: "string" }
61+
- { label: "Aliases", name: "aliases", widget: "string" }
62+
- {
63+
label: "Publish Date",
64+
name: "date",
65+
widget: "datetime",
66+
format: "YYYY-MM-DD",
67+
time_format: false,
68+
}
69+
- {
70+
label: "Expiry Date",
71+
name: "expirydate",
72+
widget: "datetime",
73+
format: "YYYY-MM-DD",
74+
time_format: false,
75+
required: false,
76+
default: "",
77+
}
78+
- { label: "Image", name: "cover", widget: "image", required: false }
79+
- { label: "Body", name: "body", widget: "markdown" }
80+
- { label: "Draft", name: "draft", widget: "boolean", default: true }
81+
- { label: "Tags", name: "tags", widget: "list" }
5682
- name: "work" # Used in routes, ie.: /admin/collections/:slug/edit
5783
label: "Work" # Used in the UI, ie.: "New Post"
5884
folder: "site/content/work" # The path to the folder where the documents are stored
5985
media_folder: "."
6086
path: "{{slug}}/index" # Each document is inside a folder with the slug name.
6187
create: true # Allow users to create new documents in this collection
6288
fields: # The fields each document in this collection have
63-
- {label: "Title", name: "title", widget: "string"}
64-
- {label: "Weight", name: "weight", widget: "number", required: false}
65-
- {label: "Url", name: "url", widget: "string"}
66-
- {label: "Publish Date", name: "date", widget: "datetime", format: "YYYY-MM-DD", timeFormat: false}
67-
- {label: "Expiry Date", name: "expirydate", widget: "datetime", format: "YYYY-MM-DD", timeFormat: false, required: false, default: ''}
68-
- {label: "Image", name: "cover", widget: "image", required: false}
69-
- {label: "Body", name: "body", widget: "markdown"}
70-
- {label: "Draft", name: "draft", widget: "boolean", default: true}
71-
- {label: "Tags", name: "tags", widget: "list"}
89+
- { label: "Title", name: "title", widget: "string" }
90+
- { label: "Weight", name: "weight", widget: "number", required: false }
91+
- { label: "Url", name: "url", widget: "string" }
92+
- {
93+
label: "Publish Date",
94+
name: "date",
95+
widget: "datetime",
96+
format: "YYYY-MM-DD",
97+
time_format: false,
98+
}
99+
- {
100+
label: "Expiry Date",
101+
name: "expirydate",
102+
widget: "datetime",
103+
format: "YYYY-MM-DD",
104+
time_format: false,
105+
required: false,
106+
default: "",
107+
}
108+
- { label: "Image", name: "cover", widget: "image", required: false }
109+
- { label: "Body", name: "body", widget: "markdown" }
110+
- { label: "Draft", name: "draft", widget: "boolean", default: true }
111+
- { label: "Tags", name: "tags", widget: "list" }
72112
- name: "home"
73113
label: "Home"
74114
files:
75115
- file: "site/content/_index.html"
76116
label: "Home Page"
77117
name: "home"
78118
fields:
79-
- {label: Title, name: title, widget: string}
80-
- {label: Body, name: body, widget: text}
119+
- { label: Title, name: title, widget: string }
120+
- { label: Body, name: body, widget: text }
81121
- name: "team"
82122
label: "Team settings"
83123
media_folder: "/site/content/team"
@@ -92,17 +132,37 @@ collections: # A list of collections the CMS should be able to edit
92132
name: team
93133
widget: list
94134
fields:
95-
- {label: Name, name: name, widget: string}
96-
- {label: Title, name: title, widget: string}
97-
- {label: Description, name: description, widget: string, required: false}
98-
- {label: Github, name: github, widget: string, required: false}
99-
- {label: Gitlab, name: gitlab, widget: string, required: false}
100-
- {label: Linkedin, name: linkedin, widget: string, required: false}
101-
- {label: Malt, name: malt, widget: string, required: false}
102-
- {label: Mastodon, name: mastodon, widget: string, required: false}
103-
- {label: Photo, name: photo, widget: "image", required: false}
104-
- {label: Steam, name: steam, widget: string, required: false}
105-
- {label: Twitter, name: twitter, widget: string, required: false}
135+
- { label: Name, name: name, widget: string }
136+
- { label: Title, name: title, widget: string }
137+
- {
138+
label: Description,
139+
name: description,
140+
widget: string,
141+
required: false,
142+
}
143+
- { label: Github, name: github, widget: string, required: false }
144+
- { label: Gitlab, name: gitlab, widget: string, required: false }
145+
- {
146+
label: Linkedin,
147+
name: linkedin,
148+
widget: string,
149+
required: false,
150+
}
151+
- { label: Malt, name: malt, widget: string, required: false }
152+
- {
153+
label: Mastodon,
154+
name: mastodon,
155+
widget: string,
156+
required: false,
157+
}
158+
- { label: Photo, name: photo, widget: "image", required: false }
159+
- { label: Steam, name: steam, widget: string, required: false }
160+
- {
161+
label: Twitter,
162+
name: twitter,
163+
widget: string,
164+
required: false,
165+
}
106166
- name: "site_settings"
107167
label: "Site Settings"
108168
files:
@@ -115,21 +175,31 @@ collections: # A list of collections the CMS should be able to edit
115175
name: cloud
116176
widget: list
117177
fields:
118-
- {label: Text, name: text, widget: string}
119-
- {label: Poids, name: weight, widget: number}
120-
- {label: Réassurance, name: label, widget: string}
178+
- { label: Text, name: text, widget: string }
179+
- { label: Poids, name: weight, widget: number }
180+
- { label: Réassurance, name: label, widget: string }
121181
- file: "site/data/menu.json"
122182
label: Menu
123183
name: menu
124184
fields:
125-
- {label: Links, name: links, widget: list, fields: [{label: Name, name: name, widget: string}, {label: Id, name: id, widget: string}, {label: Url, name: url, widget: string}]}
185+
- {
186+
label: Links,
187+
name: links,
188+
widget: list,
189+
fields:
190+
[
191+
{ label: Name, name: name, widget: string },
192+
{ label: Id, name: id, widget: string },
193+
{ label: Url, name: url, widget: string },
194+
],
195+
}
126196
- file: "site/hugo.toml"
127197
label: Hugo Config
128198
name: config
129199
editor:
130200
preview: false
131201
fields:
132-
- {label: Site Title, name: title, widget: string}
202+
- { label: Site Title, name: title, widget: string }
133203
- label: Params
134204
name: params
135205
widget: object

src/js/cms.js

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,72 @@ CMS.registerPreviewTemplate("home", HomePreview);
1414
CMS.registerPreviewTemplate("post", PostPreview);
1515
CMS.registerPreviewTemplate("footer", FooterPreview);
1616

17-
1817
CMS.registerEditorComponent({
19-
// Internal id of the component
20-
id: "lightbox-image",
21-
// Visible label
22-
label: "Lightbox Image",
23-
// Fields the user need to fill out when adding an instance of the component
24-
fields: [
25-
{
26-
name: "title",
27-
label: "Title",
28-
widget: "string"
29-
},
30-
{
31-
name: "group",
32-
label: "Group",
33-
widget: "string"
34-
},
35-
{
36-
name: "image",
37-
label: "Image",
38-
widget: "image"
39-
},
40-
],
41-
// Regex pattern used to search for instances of this block in the markdown document.
42-
// Patterns are run in a multiline environment (against the entire markdown document),
43-
// and so generally should make use of the multiline flag (`m`). If you need to capture
44-
// newlines in your capturing groups, you can either use something like
45-
// `([\S\s]*)`, or you can additionally enable the "dot all" flag (`s`),
46-
// which will cause `(.*)` to match newlines as well.
47-
//
48-
// Additionally, it's recommended that you use non-greedy capturing groups (e.g.
49-
// `(.*?)` vs `(.*)`), especially if matching against newline characters.
50-
pattern: /^-![(.*)]\((.*?) (.*?)\)$/ms,
51-
// Given a RegExp Match object
52-
// (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#return_value),
53-
// return an object with one property for each field defined in `fields`.
54-
//
55-
// This is used to populate the custom widget in the markdown editor in the CMS.
56-
fromBlock: function (match) {
57-
return {
58-
title: match[1],
59-
image: match[2],
60-
group: match[3]
61-
};
18+
// Internal id of the component
19+
id: "lightbox-image",
20+
// Visible label
21+
label: "Lightbox Image",
22+
// Fields the user need to fill out when adding an instance of the component
23+
fields: [
24+
{
25+
name: "title",
26+
label: "Title",
27+
widget: "string",
28+
},
29+
{
30+
name: "group",
31+
label: "Group",
32+
widget: "string",
33+
},
34+
{
35+
name: "image",
36+
label: "Image",
37+
widget: "image",
6238
},
63-
// Given an object with one property for each field defined in `fields`,
64-
// return the string you wish to be inserted into your markdown.
65-
//
66-
// This is used to serialize the data from the custom widget to the
67-
// markdown document
68-
toBlock: function (data) {
69-
return `
39+
],
40+
// Regex pattern used to search for instances of this block in the markdown document.
41+
// Patterns are run in a multiline environment (against the entire markdown document),
42+
// and so generally should make use of the multiline flag (`m`). If you need to capture
43+
// newlines in your capturing groups, you can either use something like
44+
// `([\S\s]*)`, or you can additionally enable the "dot all" flag (`s`),
45+
// which will cause `(.*)` to match newlines as well.
46+
//
47+
// Additionally, it's recommended that you use non-greedy capturing groups (e.g.
48+
// `(.*?)` vs `(.*)`), especially if matching against newline characters.
49+
pattern: /^-![(.*)]\((.*?) (.*?)\)$/ms,
50+
// Given a RegExp Match object
51+
// (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#return_value),
52+
// return an object with one property for each field defined in `fields`.
53+
//
54+
// This is used to populate the custom widget in the markdown editor in the CMS.
55+
fromBlock: function (match) {
56+
return {
57+
title: match[1],
58+
image: match[2],
59+
group: match[3],
60+
};
61+
},
62+
// Given an object with one property for each field defined in `fields`,
63+
// return the string you wish to be inserted into your markdown.
64+
//
65+
// This is used to serialize the data from the custom widget to the
66+
// markdown document
67+
toBlock: function (data) {
68+
return `
7069
<a style="display: inline" href="${data.image}" data-lightbox="${data.group}" title="${data.title}">
7170
<img class="medium" src="${data.image}" alt="${data.title}">
7271
</a>
7372
`;
74-
},
75-
// Preview output for this component. Can either be a string or a React component
76-
// (component gives better render performance)
77-
toPreview: function (data) {
78-
return `
73+
},
74+
// Preview output for this component. Can either be a string or a React component
75+
// (component gives better render performance)
76+
toPreview: function (data) {
77+
return `
7978
<a style="display: inline" href="${data.image}" data-lightbox="${data.group}" title="${data.title}">
8079
<img class="medium" src="${data.image}" alt="${data.title}">
8180
</a>
8281
`;
83-
}
82+
},
8483
});
8584

86-
8785
CMS.init();

0 commit comments

Comments
 (0)