fix: paths p2
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
77
src/lib.ts
77
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<string, unknown> | null =>
|
||||
typeof value === "object" && value !== null ? (value as Record<string, unknown>) : null;
|
||||
|
||||
const asString = (value: unknown): string | null =>
|
||||
typeof value === "string" && value.length > 0 ? value : null;
|
||||
|
||||
const getLatestManifestFromAo = async (): Promise<string | null> => {
|
||||
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<ManifestPost[]> => {
|
||||
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})`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user