Parse marker shortcodes (WIP)

This commit is contained in:
Nicolò P 2025-10-24 10:27:28 +02:00
parent 00cedfeb85
commit 952dc3f841
4 changed files with 31 additions and 3 deletions

View File

@ -26,7 +26,7 @@
<script src="js/index.js" type="module"></script> <script src="js/index.js" type="module"></script>
<title>WebGIS Isola di Capri</title> <title>WebGIS Isola di Capri</title>
</head> </head>
<body data-controller="menu" <body data-controller="menu modal"
data-action="menu-ready@document->menu#buildMenu menu-ready@document->menu#buildCartographyMenu"> data-action="menu-ready@document->menu#buildMenu menu-ready@document->menu#buildCartographyMenu">
<nav class="navbar mb-0" role="navigation"> <nav class="navbar mb-0" role="navigation">
<div class="navbar-brand"> <div class="navbar-brand">

View File

@ -62,7 +62,7 @@ export class Reuse {
imageContainer.innerHTML = '<p class="has-text-centered">Nessuna risorsa visuale disponibile</p>'; imageContainer.innerHTML = '<p class="has-text-centered">Nessuna risorsa visuale disponibile</p>';
} }
/** /**
* @param {number} recordId * @param {Number} recordId
*/ */
async biblio(recordId) { async biblio(recordId) {
let {citations, biblioElements} = await Utils.buildBibliography('reuse', recordId); let {citations, biblioElements} = await Utils.buildBibliography('reuse', recordId);

View File

@ -1,3 +1,4 @@
import Utils from "./utils.js";
/** /**
* Component to render data for site sheet * Component to render data for site sheet
* @class SiteSheet * @class SiteSheet
@ -60,6 +61,9 @@ export class SiteSheet {
} }
renderShort() { renderShort() {
// TEST
const shortDesc = Utils.parseMarkers(this._siteData.shortDescription);
return ` return `
<div class="container p-3"> <div class="container p-3">
<p class="p-2"> <p class="p-2">
@ -81,7 +85,7 @@ export class SiteSheet {
<strong>Località generica:</strong> ${this._siteData.genericPlace} <strong>Località generica:</strong> ${this._siteData.genericPlace}
</p> </p>
<p class="mt-4 pl-2 pr-5"> <p class="mt-4 pl-2 pr-5">
${this._siteData.shortDescription} ${shortDesc}
</p> </p>
<p class="mt-4 pl-2 pr-5"> <p class="mt-4 pl-2 pr-5">
<span class="icon has-text-link"> <span class="icon has-text-link">

View File

@ -144,6 +144,30 @@ Utils.buildBibliography = async function(recordUri, recordId) {
return bibliography; return bibliography;
} }
/**
*
* @param {String} text - The content text from database
* Parse marker strings (pseudo-shortcodes) and convert them
* to Stimulus links
*/
Utils.parseMarkers = function(text) {
const regex = /(?<marker>\[marker coords=\"(?<coords>[\d\s\.]+)\"\](?<content>[\w\s\.;:\-]+)\[\/marker\])/mig;
let matches = [...text.matchAll(regex)];
if (matches.length) {
matches.forEach(match => {
const replacement = `
<a data-action="marker#go modal#close" data-controller="marker" data-marker-coords-value="${match.groups.coords}">
${match.groups.content}
</a>
`;
text = text.replace(match.groups.marker, replacement);
});
}
return text;
}
Utils.fetchData = async function(url) { Utils.fetchData = async function(url) {
return await fetch(url).then(res => res.ok ? res.json() : new Error()) return await fetch(url).then(res => res.ok ? res.json() : new Error())
.catch(err => console.log(err)); .catch(err => console.log(err));