Parse marker shortcodes (WIP)
This commit is contained in:
parent
00cedfeb85
commit
952dc3f841
@ -26,7 +26,7 @@
|
||||
<script src="js/index.js" type="module"></script>
|
||||
<title>WebGIS Isola di Capri</title>
|
||||
</head>
|
||||
<body data-controller="menu"
|
||||
<body data-controller="menu modal"
|
||||
data-action="menu-ready@document->menu#buildMenu menu-ready@document->menu#buildCartographyMenu">
|
||||
<nav class="navbar mb-0" role="navigation">
|
||||
<div class="navbar-brand">
|
||||
|
||||
@ -62,7 +62,7 @@ export class Reuse {
|
||||
imageContainer.innerHTML = '<p class="has-text-centered">Nessuna risorsa visuale disponibile</p>';
|
||||
}
|
||||
/**
|
||||
* @param {number} recordId
|
||||
* @param {Number} recordId
|
||||
*/
|
||||
async biblio(recordId) {
|
||||
let {citations, biblioElements} = await Utils.buildBibliography('reuse', recordId);
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import Utils from "./utils.js";
|
||||
/**
|
||||
* Component to render data for site sheet
|
||||
* @class SiteSheet
|
||||
@ -60,6 +61,9 @@ export class SiteSheet {
|
||||
}
|
||||
|
||||
renderShort() {
|
||||
// TEST
|
||||
const shortDesc = Utils.parseMarkers(this._siteData.shortDescription);
|
||||
|
||||
return `
|
||||
<div class="container p-3">
|
||||
<p class="p-2">
|
||||
@ -81,7 +85,7 @@ export class SiteSheet {
|
||||
<strong>Località generica:</strong> ${this._siteData.genericPlace}
|
||||
</p>
|
||||
<p class="mt-4 pl-2 pr-5">
|
||||
${this._siteData.shortDescription}
|
||||
${shortDesc}
|
||||
</p>
|
||||
<p class="mt-4 pl-2 pr-5">
|
||||
<span class="icon has-text-link">
|
||||
|
||||
@ -144,6 +144,30 @@ Utils.buildBibliography = async function(recordUri, recordId) {
|
||||
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) {
|
||||
return await fetch(url).then(res => res.ok ? res.json() : new Error())
|
||||
.catch(err => console.log(err));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user