Skip to content

Commit

Permalink
Adding support for federated urls in fragments block to centralisation
Browse files Browse the repository at this point in the history
  • Loading branch information
bandana147 committed Jul 23, 2024
1 parent 9a8d592 commit 9e5d300
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions libs/blocks/fragment/fragment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable max-classes-per-file */
import { createTag, getConfig, loadArea, localizeLink } from '../../utils/utils.js';
import { getFederatedUrl } from '../../utils/federated.js';

const fragMap = {};

Expand Down Expand Up @@ -90,11 +91,11 @@ export default async function init(a) {
}

const { customFetch } = await import('../../utils/helpers.js');
const resp = await customFetch({ resource: `${a.href}.plain.html`, withCacheRules: true })
const resp = await customFetch({ resource: `${getFederatedUrl(a.href)}.plain.html`, withCacheRules: true })
.catch(() => ({}));

if (!resp?.ok) {
window.lana?.log(`Could not get fragment: ${a.href}.plain.html`);
window.lana?.log(`Could not get fragment: ${getFederatedUrl(a.href)}.plain.html`);
return;
}

Expand All @@ -106,7 +107,7 @@ export default async function init(a) {
const sections = doc.querySelectorAll('body > div');

if (!sections.length) {
window.lana?.log(`Could not make fragment: ${a.href}.plain.html`);
window.lana?.log(`Could not make fragment: ${getFederatedUrl(a.href)}.plain.html`);
return;
}

Expand Down

0 comments on commit 9e5d300

Please sign in to comment.