diff --git a/.codex b/.codex new file mode 100644 index 0000000..e69de29 diff --git a/src/App.tsx b/src/App.tsx index 3f310c0..83edc70 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -121,7 +121,7 @@ function BlisterLoader() { function App() { const [posts, setPosts] = useState([]); - const [state, setState] = useState("idle"); + const [state, setState] = useState("loading"); const [error, setError] = useState(""); useEffect(() => { @@ -343,15 +343,31 @@ function PostPage({ const permalink = post ? toPermalinkUrl(`/${post.slug}`) : toPermalinkUrl(location.pathname); + const metadataTitle = + state === "loading" + ? `${BLOG_NAME} | Loading` + : state === "error" + ? `${BLOG_NAME} | Error` + : post + ? `${title} | ${BLOG_NAME}` + : `${BLOG_NAME} | Post Not Found`; + const metadataDescription = + state === "loading" + ? `Loading ${BLOG_NAME}...` + : state === "error" + ? manifestError || BLOG_DEFAULT_DESCRIPTION + : post + ? description + : `Post not found on ${BLOG_NAME}.`; usePageMetadata({ - title: post ? `${title} | ${BLOG_NAME}` : `${BLOG_NAME} | Post Not Found`, - description, + title: metadataTitle, + description: metadataDescription, path: location.pathname, image: bannerTxId ? arweaveUrl(bannerTxId) : undefined, - type: "article", - publishedTime: postFrontmatter.date || post?.publishedAt, - modifiedTime: postFrontmatter.updated || post?.updated || undefined + type: post ? "article" : "website", + publishedTime: post ? postFrontmatter.date || post.publishedAt : undefined, + modifiedTime: post ? postFrontmatter.updated || post.updated || undefined : undefined }); if (state === "loading") return ; diff --git a/src/lib.ts b/src/lib.ts index c66e43e..f907c5e 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -113,14 +113,24 @@ const getLatestManifestFromAo = async (): Promise => { }; export const loadManifest = async (): Promise => { - const manifestTxId = (await getLatestManifestFromAo()) ?? MANIFEST_TX_ID; - const response = await fetch(arweaveUrl(manifestTxId)); - if (!response.ok) { - throw new Error(`Failed to load manifest (${response.status})`); - } + const loadByTxId = async (manifestTxId: string): Promise => { + const response = await fetch(arweaveUrl(manifestTxId)); + if (!response.ok) { + throw new Error(`Failed to load manifest (${response.status})`); + } + const payload: unknown = await response.json(); + return parseManifest(payload); + }; - const payload: unknown = await response.json(); - return parseManifest(payload); + try { + return await loadByTxId(MANIFEST_TX_ID); + } catch (manifestError) { + const latestManifestTxId = await getLatestManifestFromAo(); + if (!latestManifestTxId || latestManifestTxId === MANIFEST_TX_ID) { + throw manifestError; + } + return loadByTxId(latestManifestTxId); + } }; const isObject = (value: unknown): value is Record =>