diff --git a/scripts/deploy.mjs b/scripts/deploy.mjs index b9290c5..aaf0217 100644 --- a/scripts/deploy.mjs +++ b/scripts/deploy.mjs @@ -228,83 +228,8 @@ async function resolveBlogManifestTxId() { return match?.[1] || ""; } -const asObject = (value) => (typeof value === "object" && value !== null ? value : null); -const asString = (value) => (typeof value === "string" && value.length > 0 ? value : null); - -async function resolveAoConfig() { - const source = await fs.readFile(sourceConfigPath, "utf8"); - const aoUrlMatch = source.match(/AO_URL\s*=\s*"([^"]+)"/); - const aoProcessIdMatch = source.match(/AO_PROCESS_ID\s*=\s*"([^"]+)"/); - return { - aoUrl: aoUrlMatch?.[1] || "", - aoProcessId: aoProcessIdMatch?.[1] || "" - }; -} - -async function getLatestManifestFromAo() { - const { aoUrl, aoProcessId } = await resolveAoConfig(); - if (!aoUrl || !aoProcessId) return ""; - - try { - const pushResponse = await fetch(`${aoUrl}/${aoProcessId}~process@1.0/push`, { - method: "POST", - headers: { - "content-type": "application/json", - "signing-format": "ans104", - "accept-bundle": "true", - "require-codec": "application/json" - }, - body: JSON.stringify({ - Type: "Message", - "Data-Protocol": "ao", - Variant: "ao.N.1", - Action: "Get", - target: aoProcessId, - data: "1984" - }) - }); - if (!pushResponse.ok) return ""; - - const pushPayload = await pushResponse.json(); - const slot = asString(asObject(pushPayload)?.slot); - if (!slot) return ""; - - const computeResponse = await fetch(`${aoUrl}/${aoProcessId}~process@1.0/compute=${slot}`, { - method: "POST", - headers: { - "content-type": "application/json", - "signing-format": "ans104", - "accept-bundle": "true", - "require-codec": "application/json" - }, - body: JSON.stringify({ - target: aoProcessId, - data: "1984" - }) - }); - if (!computeResponse.ok) return ""; - - const computePayload = await computeResponse.json(); - const body = asObject(asObject(asObject(computePayload)?.results)?.json)?.body; - const parsedBody = typeof body === "string" ? asObject(JSON.parse(body)) : asObject(body); - const messages = Array.isArray(parsedBody?.Messages) ? parsedBody.Messages : []; - - for (const message of messages) { - const tags = Array.isArray(asObject(message)?.Tags) ? asObject(message)?.Tags : []; - for (const tag of tags) { - const tagObject = asObject(tag); - const name = asString(tagObject?.name) ?? asString(tagObject?.Name); - const value = asString(tagObject?.value) ?? asString(tagObject?.Value); - if (name === "LatestManifestId" && value) return value; - } - } - } catch {} - - return ""; -} - async function resolvePostSlugs(gateway) { - const blogManifestTxId = (await getLatestManifestFromAo()) || (await resolveBlogManifestTxId()); + const blogManifestTxId = await resolveBlogManifestTxId(); if (!blogManifestTxId) return []; try { @@ -399,6 +324,7 @@ async function main() { manifest: "arweave/paths", version: "0.2.0", index: { path: "index.html" }, + fallback: { id: indexTxId }, paths: pathMap }; diff --git a/src/config.ts b/src/config.ts index f852d56..6029f28 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,5 @@ -export const BLOG_NAME = "hyperzine"; -export const MANIFEST_TX_ID = "Zjc1hce_CgyNrq7qqufrJ20ra7IvNU7t8EnK2QA1EHE"; +export const BLOG_NAME = "Hyperzine"; +export const MANIFEST_TX_ID = "VKzmyjIucGm2t9XBYNXpP0aolCD10CfEkivJvRnTpp4"; 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 49950b1..c4e0802 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,12 +1,7 @@ import DOMPurify from "dompurify"; import { marked } from "marked"; import { parse as parseYaml } from "yaml"; -import { - AO_PROCESS_ID, - AO_URL, - ARWEAVE_GATEWAY, - MANIFEST_TX_ID -} from "./config"; +import { ARWEAVE_GATEWAY, MANIFEST_TX_ID } from "./config"; import { parseManifest, type Frontmatter, type ManifestPost } from "./types"; const formatDate = (date: string): string => @@ -30,76 +25,8 @@ export const getReadableDate = (date?: string | null): string | null => { return formatDate(date); }; -const asObject = (value: unknown): Record | null => - typeof value === "object" && value !== null ? (value as Record) : null; - -const asString = (value: unknown): string | null => - typeof value === "string" && value.length > 0 ? value : null; - -const getLatestManifestFromAo = async (): Promise => { - try { - const pushResponse = await fetch(`${AO_URL}/${AO_PROCESS_ID}~process@1.0/push`, { - method: "POST", - headers: { - "content-type": "application/json", - "signing-format": "ans104", - "accept-bundle": "true", - "require-codec": "application/json" - }, - body: JSON.stringify({ - Type: "Message", - "Data-Protocol": "ao", - Variant: "ao.N.1", - Action: "Get", - target: AO_PROCESS_ID, - data: "1984" - }) - }); - if (!pushResponse.ok) return null; - - const pushPayload = (await pushResponse.json()) as unknown; - const slot = asString(asObject(pushPayload)?.slot); - if (!slot) return null; - - const computeResponse = await fetch(`${AO_URL}/${AO_PROCESS_ID}~process@1.0/compute=${slot}`, { - method: "POST", - headers: { - "content-type": "application/json", - "signing-format": "ans104", - "accept-bundle": "true", - "require-codec": "application/json" - }, - body: JSON.stringify({ - target: AO_PROCESS_ID, - data: "1984" - }) - }); - if (!computeResponse.ok) return null; - - const computePayload = (await computeResponse.json()) as unknown; - const body = asObject(asObject(asObject(computePayload)?.results)?.json)?.body; - const parsedBody = typeof body === "string" ? asObject(JSON.parse(body)) : asObject(body); - const messages = Array.isArray(parsedBody?.Messages) ? parsedBody.Messages : []; - - for (const message of messages) { - const tags = Array.isArray(asObject(message)?.Tags) ? (asObject(message)?.Tags as unknown[]) : []; - for (const tag of tags) { - const tagObject = asObject(tag); - const name = asString(tagObject?.name) ?? asString(tagObject?.Name); - const value = asString(tagObject?.value) ?? asString(tagObject?.Value); - if (name === "LatestManifestId" && value) return value; - } - } - - return null; - } catch { - return null; - } -}; - export const loadManifest = async (): Promise => { - const manifestTxId = (await getLatestManifestFromAo()) ?? MANIFEST_TX_ID; - const response = await fetch(arweaveUrl(manifestTxId)); + const response = await fetch(arweaveUrl(MANIFEST_TX_ID)); if (!response.ok) { throw new Error(`Failed to load manifest (${response.status})`); }