Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nx/blocks/snapshot-admin/utils/fragments.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-continue */
import { DA_ORIGIN } from '../../../public/utils/constants.js';
import { daFetch } from '../../../utils/daFetch.js';
import { appendHtmlUnlessExtension } from './utils.js';

const FRAGMENT_SELECTOR = 'a[href*="/fragments/"], .fragment a';

Expand Down Expand Up @@ -51,8 +52,7 @@ export async function findFragments(resources, org, site) {
if (visited.has(path)) return [];
visited.add(path);

const extPath = path.endsWith('.json') ? path : `${path}.html`;
const daUrl = `${DA_ORIGIN}/source/${org}/${site}${extPath}`;
const daUrl = `${DA_ORIGIN}/source/${org}/${site}${appendHtmlUnlessExtension(path)}`;

try {
const resp = await daFetch(daUrl);
Expand Down
9 changes: 7 additions & 2 deletions nx/blocks/snapshot-admin/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ export async function updatePaths(name, currPaths, editedHrefs) {
return formatResources(name, toFormat);
}

export function appendHtmlUnlessExtension(pathname) {
const basename = pathname.slice(pathname.lastIndexOf('/') + 1);
return /\.[^./]+$/.test(basename) ? pathname : `${pathname}.html`;
}

export async function copyManifest(name, resources, direction, mode = 'merge') {
const copyUrl = async (url) => {
if (mode === 'overwrite' || !url.source.endsWith('.html')) {
Expand All @@ -202,7 +207,7 @@ export async function copyManifest(name, resources, direction, mode = 'merge') {

const path = url.pathname.endsWith('/') ? `${url.pathname}index` : url.pathname;

const extPath = path.endsWith('.json') ? path : `${path}.html`;
const extPath = appendHtmlUnlessExtension(path);

const main = `/${org}/${site}${extPath}`;
const fork = `/${org}/${site}/.snapshots/${name}${extPath}`;
Expand Down Expand Up @@ -314,7 +319,7 @@ const getConfig = async (_org, _site) => {
};

export async function checkSnapshotSource(name, path) {
const extPath = path.endsWith('.json') ? path : `${path}.html`;
const extPath = appendHtmlUnlessExtension(path);
const url = `${DA_ORIGIN}/source/${org}/${site}/.snapshots/${name}${extPath}`;
try {
const resp = await daFetch(url, { method: 'HEAD' });
Expand Down
Loading