Skip to content

Commit

Permalink
アコーディオンのショートコードを実装
Browse files Browse the repository at this point in the history
  • Loading branch information
aiotter committed Dec 19, 2021
1 parent 910b31a commit dec95aa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions layouts/shortcodes/accordion.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<details><summary>{{ .Get "summary" }}</summary> {{ .Inner }}</details>
1 change: 1 addition & 0 deletions static/admin/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ collections:
- bulleted-list
- numbered-list
editor_components:
- accordion
- image_shortcode
- large
- youtube
Expand Down
30 changes: 30 additions & 0 deletions static/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@
return `<span style="font-size: large;">${obj.content}</span>`;
},
});

CMS.registerEditorComponent({
id: "accordion",
label: "Accordion",
fields: [
{
name: "summary",
label: "summary",
widget: "string",
},
{
name: "content",
label: "content",
widget: "markdown",
},
],
pattern: /{{< accordion summary="([^"]*)" >}}(.*?){{<\/ accordion >}}/,
fromBlock: function(match) {
return {
summary: match[1],
content: match[2],
};
},
toBlock: function(obj) {
return `{{< accordion summary="${obj.summary ?? ""}" >}}${obj.content ?? ""}{{</ accordion >}}`;
},
toPreview: function(obj) {
return `<details><summary>${obj.summary}</summary>${obj.content}</details>`;
},
});
</script>
</body>
</html>

0 comments on commit dec95aa

Please sign in to comment.