diff --git a/scripts/deploy.mjs b/scripts/deploy.mjs index 3e9692f..a943e87 100644 --- a/scripts/deploy.mjs +++ b/scripts/deploy.mjs @@ -223,12 +223,6 @@ async function createUploader(uploadMode, arweave, jwk) { }; } -async function resolveBlogManifestTxId() { - const source = await fs.readFile(sourceConfigPath, "utf8"); - const match = source.match(/MANIFEST_TX_ID\s*=\s*"([^"]+)"/); - return match?.[1] || ""; -} - async function resolveBlogManifestReferenceName() { const source = await fs.readFile(sourceConfigPath, "utf8"); const match = source.match(/MANIFEST_REFERENCE_NAME\s*=\s*"([^"]+)"/); @@ -344,8 +338,7 @@ async function fetchPostSlugs(gateway, blogManifestTxId) { async function resolvePostSlugs(gateway) { const candidates = [ await getLatestManifestFromReference(gateway), - await getLatestManifestFromAo(), - await resolveBlogManifestTxId() + await getLatestManifestFromAo() ].filter(Boolean); for (const blogManifestTxId of candidates) { diff --git a/scripts/prerender-meta.mjs b/scripts/prerender-meta.mjs index eae7361..df6cac7 100644 --- a/scripts/prerender-meta.mjs +++ b/scripts/prerender-meta.mjs @@ -12,8 +12,7 @@ const DEFAULTS = { BLOG_SITE_URL: "https://hyperzine.xyz", BLOG_DEFAULT_DESCRIPTION: "hyperzine", ARWEAVE_GATEWAY: "https://arweave.net", - MANIFEST_REFERENCE_NAME: "", - MANIFEST_TX_ID: "" + MANIFEST_REFERENCE_NAME: "" }; const asObject = (value) => (typeof value === "object" && value !== null ? value : null); @@ -54,8 +53,7 @@ const parseConfig = async () => { BLOG_SITE_URL: pick("BLOG_SITE_URL"), BLOG_DEFAULT_DESCRIPTION: pick("BLOG_DEFAULT_DESCRIPTION"), ARWEAVE_GATEWAY: pick("ARWEAVE_GATEWAY"), - MANIFEST_REFERENCE_NAME: pick("MANIFEST_REFERENCE_NAME"), - MANIFEST_TX_ID: pick("MANIFEST_TX_ID") + MANIFEST_REFERENCE_NAME: pick("MANIFEST_REFERENCE_NAME") }; }; @@ -121,10 +119,10 @@ const parseManifest = (input) => { }); }; -const fetchManifestPosts = async (manifestTxId) => { +const fetchManifestPosts = async (config, manifestTxId) => { if (!manifestTxId) return []; - const url = `https://arweave.net/${manifestTxId}`; - const response = await fetch(url, { cache: "no-store" }); + const gateway = (config.ARWEAVE_GATEWAY || DEFAULTS.ARWEAVE_GATEWAY).replace(/\/+$/, ""); + const response = await fetch(`${gateway}/${manifestTxId}`, { cache: "no-store" }); if (!response.ok) throw new Error(`Manifest fetch failed (${response.status})`); const payload = await response.json(); const posts = parseManifest(payload); @@ -132,36 +130,17 @@ const fetchManifestPosts = async (manifestTxId) => { }; const resolveManifestTxId = async (config) => { - if (config.MANIFEST_REFERENCE_NAME) { - try { - const names = new ReferenceClient({ gateway: config.ARWEAVE_GATEWAY || DEFAULTS.ARWEAVE_GATEWAY }); - const value = await names.resolveName(config.MANIFEST_REFERENCE_NAME); - if (typeof value === "string" && value.length > 0) return value; - throw new Error(`Reference ${config.MANIFEST_REFERENCE_NAME} did not resolve to a manifest id`); - } catch (error) { - console.warn( - `[prerender-meta] Falling back to configured manifest; reference ${config.MANIFEST_REFERENCE_NAME} failed: ${error.message}` - ); - } - } - - return config.MANIFEST_TX_ID; + if (!config.MANIFEST_REFERENCE_NAME) return ""; + const names = new ReferenceClient({ gateway: config.ARWEAVE_GATEWAY || DEFAULTS.ARWEAVE_GATEWAY }); + const value = await names.resolveName(config.MANIFEST_REFERENCE_NAME); + if (typeof value === "string" && value.length > 0) return value; + throw new Error(`Reference ${config.MANIFEST_REFERENCE_NAME} did not resolve to a manifest id`); }; const fetchCurrentManifestPosts = async (config) => { const manifestTxId = await resolveManifestTxId(config); if (!manifestTxId) return []; - - try { - return (await fetchManifestPosts(manifestTxId)).posts; - } catch (error) { - if (!config.MANIFEST_REFERENCE_NAME || manifestTxId === config.MANIFEST_TX_ID) throw error; - console.warn( - `[prerender-meta] Falling back to configured manifest; reference manifest ${manifestTxId} failed: ${error.message}` - ); - } - - return config.MANIFEST_TX_ID ? (await fetchManifestPosts(config.MANIFEST_TX_ID)).posts : []; + return (await fetchManifestPosts(config, manifestTxId)).posts; }; const buildMetaTags = ({ diff --git a/src/config.ts b/src/config.ts index 3b2d889..96a7eab 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,7 +5,6 @@ export const BLOG_DEFAULT_DESCRIPTION = "A blog about cyberspace decentralization"; export const BLOG_TWITTER_HANDLE = ""; export const MANIFEST_REFERENCE_NAME = "mystic"; -export const MANIFEST_TX_ID = "SShELKFa2EsiB-OJbeoNOjAIxgah9OmRhxYXBF_M9wA"; export const ARWEAVE_GATEWAY = "https://arweave.net"; export const AO_URL = "https://push-1.forward.computer"; diff --git a/src/lib.ts b/src/lib.ts index b9e9719..bb5503e 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -2,7 +2,7 @@ import DOMPurify from "dompurify"; import { marked, type Tokens } from "marked"; import { parse as parseYaml } from "yaml"; import { ReferenceClient } from "@permaweb/references"; -import { ARWEAVE_GATEWAY, MANIFEST_REFERENCE_NAME, MANIFEST_TX_ID } from "./config"; +import { ARWEAVE_GATEWAY, MANIFEST_REFERENCE_NAME } from "./config"; import { parseManifest, type Frontmatter, type ManifestPost } from "./types"; const formatDate = (date: string): string => @@ -106,26 +106,12 @@ const resolveReferenceManifestTxId = async (): Promise => { }; const loadReferenceManifest = async () => { - if (!MANIFEST_REFERENCE_NAME) return null; - - try { - return await fetchManifest(await resolveReferenceManifestTxId()); - } catch (error) { - console.warn( - `Could not load manifest reference ${MANIFEST_REFERENCE_NAME}; trying configured manifest`, - error - ); - return null; - } -}; - -const loadConfiguredManifest = async () => { - if (!MANIFEST_TX_ID) throw new Error("No manifest reference or fallback manifest configured"); - return fetchManifest(MANIFEST_TX_ID); + if (!MANIFEST_REFERENCE_NAME) throw new Error("No manifest reference configured"); + return fetchManifest(await resolveReferenceManifestTxId()); }; const loadCurrentManifest = async () => { - return (await loadReferenceManifest()) ?? (await loadConfiguredManifest()); + return loadReferenceManifest(); }; export const resolveManifestTxId = async (): Promise => {