Skip to content

Commit

Permalink
Merge pull request #1317 from hlxsites/1316-spline-fragment
Browse files Browse the repository at this point in the history
Created for spline-fragment
  • Loading branch information
davenichols-DHLS authored Dec 6, 2024
2 parents 0d4f2eb + e9ca168 commit f95eae0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions blocks/spline-viewer/spline-viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getFragmentFromFile } from '../../scripts/scripts.js';

export default async function decorate(block) {
try {
// get the content
const fragment = await getFragmentFromFile('/fragments/spline.html');
block.innerHTML = '';
const parser = new DOMParser();
const fragmentHtml = parser.parseFromString(fragment, 'text/html');
[...fragmentHtml.body.children].forEach((item) => {
block.append(item);
});
} catch (e) {
block.textContent = '';
// eslint-disable-next-line no-console
console.warn(`cannot load snippet at ${e}`);
}
}
2 changes: 2 additions & 0 deletions fragments/spline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script type="module" src="https://unpkg.com/@splinetool/[email protected]/build/spline-viewer.js"></script>
<spline-viewer url="https://prod.spline.design/UBAIdqMtOkuDExkL/scene.splinecode"></spline-viewer>
2 changes: 2 additions & 0 deletions tools/importer/transformers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import workflowCarousel from './workflowCarousel.js';
import embedScript from './embedScript.js';
import callToActionText from './callToActionText.js';
import productNotFound from './product-not-found.js';
import splineViewer from './spline-viewer.js';

// eslint-disable-next-line import/prefer-default-export
export const transformers = [
Expand Down Expand Up @@ -93,6 +94,7 @@ export const transformers = [
embedScript,
callToActionText,
productNotFound,
splineViewer,
];

export const asyncTransformers = [
Expand Down
10 changes: 10 additions & 0 deletions tools/importer/transformers/spline-viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* global WebImporter */
const splineViewer = (main, document) => {
const splineViewerEl = main.querySelector('div#spline-viewer');
if (splineViewerEl) {
const block = [['Spline Viewer'], ['']];
const table = WebImporter.DOMUtils.createTable(block, document);
splineViewerEl.replaceWith(table);
}
};
export default splineViewer;

0 comments on commit f95eae0

Please sign in to comment.