import { defaultMarkdownSerializer } from "prosemirror-markdown"; // @ts-ignore, doesn't matter. import default_md from "./default.md" with {type: "text"}; import { EditorState } from "prosemirror-state"; import type { Post } from "@/lib/types"; var data_element = document.querySelector('script#data'); // JSON {content: "# Markdown\n bla bla bla"} var editor_container = document.querySelector("#editor-container") as HTMLScriptElement; var title_input = document.querySelector("#title") as HTMLInputElement; if (!data_element) { let error = document.createElement("div"); error.className = "error"; error.innerHTML = "
It appears to be that the poor soul who programmed this page made a mistake, and the editor couldn't load your post. Please excuse him.
Try reloading the page, clearing the cache, or contacting the maintainers if none of that works.
" editor_container.appendChild(error); alert("It appears to be that the poor soul who programmed this page made a mistake, and the editor couldn't load your post. Please excuse him.\nTry reloading the page, clearing the cache, or contacting the maintainers if none of that works.") } let data = JSON.parse(data_element!.textContent); export const initial_title = title_input.value; export const initial_post = { ...data, title: initial_title, } export let last_update = { ...initial_post, ...(initial_post.published_at !== undefined && { published_at: !!initial_post.published_at }) }; const target = new URL(window.location.href).pathname; export async function publish_post() { let path = (last_update.published_at === false ? "publish" : "unpublish"); const request = await fetch(`${target}/${path}`, { method: "POST" }); const answer = await request.json(); if (answer.success) { last_update.published_at = (answer.published_at ? answer.published_at : false); alert(answer.message) return true; } else { alert(answer.error); return false; } } export async function update_post(state: EditorState) { let update = { content: defaultMarkdownSerializer.serialize(state.doc), title: title_input.value!, }; const changed: Partial