shortcode integrations
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 30s

This commit is contained in:
2025-06-09 23:55:03 +02:00
parent 61713f57f5
commit 0eafcb19a2
3 changed files with 102 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
<!--
Usage:
{{< osm lat="48.858844" lon="2.294351" zoom="15" height="400px" >}}
All parameters are optional except lat/lon.
-->
<div id="osm-map-{{ .Get "lat" }}-{{ .Get "lon" }}-{{ .Get "zoom" | default "15" }}" style="height:{{ .Get "height" | default "400px" }};"></div>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
(function() {
var mapId = "osm-map-{{ .Get "lat" }}-{{ .Get "lon" }}-{{ .Get "zoom" | default "15" }}";
if (!window._osm_maps) window._osm_maps = {};
if (!window._osm_maps[mapId]) {
var map = L.map(mapId).setView(
[{{ .Get "lat" }}, {{ .Get "lon" }}],
{{ .Get "zoom" | default "15" }}
);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([{{ .Get "lat" }}, {{ .Get "lon" }}]).addTo(map);
window._osm_maps[mapId] = map;
}
})();
</script>

View File

@@ -22,8 +22,8 @@ collections:
fields: fields:
- { label: "Layout", name: "layout", widget: "hidden", default: "post" } - { label: "Layout", name: "layout", widget: "hidden", default: "post" }
- { label: "Title", name: "title", widget: "string" } - { label: "Title", name: "title", widget: "string" }
- { label: "Summary", name: "summary", widget: "string" } - { label: "Summary", name: "summary", widget: "string", required: false }
- { label: "Description", name: "description", widget: "string" } - { label: "Description", name: "description", widget: "string", required: false }
- { - {
label: "Authors", label: "Authors",
name: "authors", name: "authors",
@@ -33,8 +33,12 @@ collections:
} }
- { label: "Date", name: "date", widget: "datetime" } - { label: "Date", name: "date", widget: "datetime" }
- { label: "Draft", name: "draft", widget: "boolean", default: true } - { label: "Draft", name: "draft", widget: "boolean", default: true }
- { label: "Cover Image", name: "image", widget: "prefixed-image" }
- { label: "Cover Image", name: "image", widget: "prefixed-image", required : false }
- { label: "Cover Style", name: "cover_style", widget: "select", options: ["basic", "big", "background", "thumbAndBackground"], default: "default" } - { label: "Cover Style", name: "cover_style", widget: "select", options: ["basic", "big", "background", "thumbAndBackground"], default: "default" }
- { label: "images", name: "images", widget: "image", multiple: true } - { label: "images", name: "images", widget: "image", multiple: true }
- { label: "Body", name: "body", widget: "markdown" } - { label: "Body", name: "body", widget: "markdown" }

View File

@@ -12,5 +12,74 @@
<!-- Include the script that builds the page and powers Decap CMS --> <!-- Include the script that builds the page and powers Decap CMS -->
<script src="https://unpkg.com/decap-cms@^3.0.0/dist/decap-cms.js"></script> <script src="https://unpkg.com/decap-cms@^3.0.0/dist/decap-cms.js"></script>
<script src="prefixed-image-widget.js"></script> <script src="prefixed-image-widget.js"></script>
<script>
// Register the OSM shortcode as an editor component
window.CMS.registerEditorComponent({
id: "osm",
label: "OpenStreetMap",
fields: [
{ name: "lat", label: "Latitude", widget: "string" },
{ name: "lon", label: "Longitude", widget: "string" },
{ name: "zoom", label: "Zoom", widget: "number", default: 15, required: false },
{ name: "height", label: "Height (e.g. 400px)", widget: "string", default: "400px", required: false }
],
pattern: /{{<\s*osm\s+lat="([^"]+)"\s+lon="([^"]+)"(?:\s+zoom="([^"]+)")?(?:\s+height="([^"]+)")?\s*>}}/,
fromBlock: function(match) {
return {
lat: match[1],
lon: match[2],
zoom: match[3] || "15",
height: match[4] || "400px"
};
},
toBlock: function(obj) {
let params = `lat="${obj.lat}" lon="${obj.lon}"`;
if (obj.zoom) params += ` zoom="${obj.zoom}"`;
if (obj.height) params += ` height="${obj.height}"`;
return `{{< osm ${params} >}}`;
},
toPreview: function(obj) {
// Simple preview (not interactive)
return `<div style="border:1px solid #ccc;padding:1em;">
<strong>OpenStreetMap Widget</strong><br>
Lat: ${obj.lat}, Lon: ${obj.lon}, Zoom: ${obj.zoom || 15}, Height: ${obj.height || "400px"}
</div>`;
}
});
// Register the carousel shortcode as an editor component
window.CMS.registerEditorComponent({
id: "carousel",
label: "Image Carousel",
fields: [
{ name: "images", label: "Images (comma-separated filenames or URLs)", widget: "string" },
{ name: "aspectRatio", label: "Aspect Ratio (e.g. 16-9)", widget: "string", required: false },
{ name: "interval", label: "Interval (ms)", widget: "number", required: false }
],
pattern: /{{<\s*carousel\s+images="([^"]+)"(?:\s+aspectRatio="([^"]+)")?(?:\s+interval="([^"]+)")?\s*>}}/,
fromBlock: function(match) {
return {
images: match[1],
aspectRatio: match[2] || "",
interval: match[3] || ""
};
},
toBlock: function(obj) {
let params = `images="${obj.images}"`;
if (obj.aspectRatio) params += ` aspectRatio="${obj.aspectRatio}"`;
if (obj.interval) params += ` interval="${obj.interval}"`;
return `{{< carousel ${params} >}}`;
},
toPreview: function(obj) {
// Simple preview (not interactive)
return `<div style="border:1px solid #ccc;padding:1em;">
<strong>Image Carousel</strong><br>
Images: ${obj.images}<br>
Aspect Ratio: ${obj.aspectRatio || "16-9"}<br>
Interval: ${obj.interval || "2000"} ms
</div>`;
}
});
</script>
</body> </body>
</html> </html>