diff --git a/backend/graph/page_helpers.go b/backend/graph/page_helpers.go index 41ba17a..1d18c07 100644 --- a/backend/graph/page_helpers.go +++ b/backend/graph/page_helpers.go @@ -25,7 +25,8 @@ const maxSlugLen = 100 // nginx or one of the SPA's own routes answers them first (see // nginx/nginx_routes.conf.template and vue/src/router/index.js), plus the // built-in canvases' page keys, whose boxes a page of the same slug would -// share. "shrines" is deliberately absent: shrine pages live under it. +// share. "shrines" is deliberately absent: /shrines and the shrine pages under +// it are all canvas pages. var reservedFirstSegments = map[string]bool{ "stp": true, "stp2": true, "index": true, "admin": true, "cv": true, "automata": true, "hotels": true, "api": true, "py": true, "radio": true, @@ -34,11 +35,6 @@ var reservedFirstSegments = map[string]bool{ "sound": true, "assets": true, "internal": true, } -// reservedSlugs are individual paths the SPA routes itself. -var reservedSlugs = map[string]bool{ - "shrines": true, -} - func validPageKey(key string) bool { return len(key) <= maxSlugLen && pageKeyPattern.MatchString(key) } @@ -49,7 +45,7 @@ func validateSlug(slug string) error { return errors.New("a page address is lower-case letters, digits and hyphens, in /-separated parts, e.g. shrines/evangelion") } first, _, _ := strings.Cut(slug, "/") - if reservedFirstSegments[first] || reservedSlugs[slug] { + if reservedFirstSegments[first] { return errors.New("that address is already used by the site") } return nil diff --git a/backend/graph/page_helpers_test.go b/backend/graph/page_helpers_test.go index bdb0fe8..392711d 100644 --- a/backend/graph/page_helpers_test.go +++ b/backend/graph/page_helpers_test.go @@ -17,7 +17,7 @@ func TestValidateSlug(t *testing.T) { {"shrines//gto", false}, // empty segment {"shrines/gto-", false}, // trailing hyphen {"shrines/../admin", false}, // dots - {"shrines", false}, // the SPA's own index + {"shrines", true}, // the index is a canvas page too {"shrines/demoman", true}, // no longer an SPA route {"admin/pages", false}, // under an SPA route {"jobs/x", false}, // under an nginx route diff --git a/vue/README.md b/vue/README.md index 4c6f152..f4bbc09 100644 --- a/vue/README.md +++ b/vue/README.md @@ -68,7 +68,8 @@ Two layout shells, defined in `src/router/index.js`: | `/` | DefaultLayout | Landing page (statically imported — it's the first paint): a box canvas, page key `index`; the old fixed page is its starter layout, `views/landing/landingLayout.js` | | `/stp` | DefaultLayout | The personal home page: an admin-editable canvas of boxes (`views/home3/`, see "The /stp canvas" below) | | `/admin`, `/admin/login` | DefaultLayout | `/admin` is guarded by `meta.requiresAdmin` | -| `/automata`, `/hotels`, `/shrines` | DefaultLayout | Each shrine under `/shrines/` is a canvas page | +| `/automata`, `/hotels` | DefaultLayout | | +| `/shrines`, `/shrines/*` | DefaultLayout | All canvas pages via the catch-all: `/shrines` is an index whose links are Link boxes placed by hand | | `/cv` | CVLayout | Light print theme. Its Jobs button goes to `/jobs/`, the separate job tracker app (`adamf/job-tracker`); nginx redirects the old `/cv/jobs` and `/cv/leads` there | | `/stp2` | (none) | Bare full-bleed mock, deliberately outside both layouts | | `:pathMatch(.*)*` | DefaultLayout | `views/canvas/CanvasPage.vue`: an admin-created canvas page if one exists at the path, else the 404 (with a "create a page here" form for admins) | @@ -209,9 +210,9 @@ renders any page's boxes. (`Landing.vue`), which is nothing but the canvas. Any other key is the slug of a **`Page`** (GraphQL type, `stores/pages.js`), an admin-created page served at `/` by the router's catch-all (`views/canvas/CanvasPage.vue`). Pages are created from - the admin panel's Pages tab, from `/shrines`, or from the 404 of the address - you want; each can start from a layout in `views/canvas/pageStarters.js` - (Blank, Shrine, Notes board). Title, address and visibility are under "Page + the admin panel's Pages tab (which also has a "New shrine" form, a blank page + under `shrines/`), or from the 404 of the address you want; each can start + from a layout in `views/canvas/pageStarters.js` (Blank, Notes board). Title, address and visibility are under "Page settings" on the page; renaming moves its boxes, deleting takes them too. The server refuses slugs that an SPA or nginx route would answer first (`validateSlug` in `backend/graph/page_helpers.go`) — add to that list when @@ -248,7 +249,9 @@ renders any page's boxes. - **Editing.** Admins get an "Edit layout" toggle at desktop width. Geometry saves on pointer release, and the box is moved locally first and put back if the save fails. `BoxEditor.vue` is the side panel. Settings save on change; - HTML is a draft that previews live and saves with Save or Ctrl/Cmd+S. + HTML is a draft that previews live and saves with Save or Ctrl/Cmd+S, or + automatically on leaving the box (selecting another, clicking empty canvas, + Done, ✕). CodeMirror is loaded only when that panel opens; the panel is teleported to ``. Image and video files dropped onto the canvas in edit mode are uploaded and @@ -307,7 +310,7 @@ in its header comment; the summary: | File | Status | | --- | --- | | `views/home3/Home3.vue` | live (`/stp`) — the box canvas; its widget boxes use **Intro3** and **Gym2** | -| `views/home/shrines/{Demoman,GTO,Evangelion,Skipskipbenben}.vue` | the old hand-written shrines (Demoman a video wall, the rest ``), unrouted; shrines are canvas pages now | +| `views/home/shrines/{Shrines,Demoman,GTO,Evangelion,Skipskipbenben}.vue` | the old `/shrines` index and hand-written shrines (Demoman a video wall, the rest ``), unrouted; shrines are canvas pages now | | `views/home/Home.vue` | legacy fixed grid that `/stp` used to be; no route. Its widgets are still live through `home3/widgetRegistry.js` | | `views/home/Intro.vue` | superseded by `Intro2.vue`; not imported | | `views/home/Gym.vue` | superseded by `Gym2.vue`; not imported | diff --git a/vue/src/router/index.js b/vue/src/router/index.js index 8a94d79..4e82a11 100644 --- a/vue/src/router/index.js +++ b/vue/src/router/index.js @@ -60,14 +60,10 @@ const router = createRouter({ name: "cheap-hotels", component: () => import("@/views/hotels/CheapHotels.vue"), }, - { - path: "shrines", - name: "shrine links", - component: () => import("@/views/home/shrines/Shrines.vue"), - }, - // Individual shrines are canvas pages, made from /shrines and - // served by the catch-all below. The old hand-written ones - // (views/home/shrines/) are unrouted. + // /shrines and the shrines under it are canvas pages, made + // from the admin panel's Pages tab and served by the catch-all + // below. The old hand-written ones (views/home/shrines/) are + // unrouted. // Anything else is an admin-created canvas page if one exists // at that address (the Page GraphQL type), else the 404. { diff --git a/vue/src/views/admin/ManagePages.vue b/vue/src/views/admin/ManagePages.vue index 3b19ffb..825a567 100644 --- a/vue/src/views/admin/ManagePages.vue +++ b/vue/src/views/admin/ManagePages.vue @@ -3,6 +3,10 @@ * Admin tab: the canvas pages made in the browser (views/canvas/). Lists them * all, admin-only ones included, and creates new ones. A page's title, * address and visibility are edited from "Page settings" on the page itself. + * + * "New shrine" is the same form with the address fixed under /shrines/. It + * starts blank and adds no link anywhere: /shrines is itself a canvas page, + * and its links are boxes put there by hand. */ import { usePagesStore } from "@/stores/pages"; import PageForm from "@/views/canvas/PageForm.vue"; @@ -44,6 +48,15 @@ async function remove(page) {

No pages yet.

+
+

New shrine

+

+ A blank page under /shrines/. Link to it from the /shrines page with a + Link box. +

+ +
+

New page

diff --git a/vue/src/views/canvas/PageForm.vue b/vue/src/views/canvas/PageForm.vue index e2d9ca4..34b53e9 100644 --- a/vue/src/views/canvas/PageForm.vue +++ b/vue/src/views/canvas/PageForm.vue @@ -2,8 +2,9 @@ /** * Create a canvas page: its address, title, a starting layout from * pageStarters.js, and whether only admins may see it. On success it opens - * the new page and emits `created`. Used on the admin panel's Pages tab, on /shrines, and on the - * 404 an admin sees at an address that has no page yet. + * the new page and emits `created`. Used on the admin panel's Pages tab + * (twice: any page, and a shrine under /shrines/) and on the 404 an admin sees + * at an address that has no page yet. */ import { ref } from "vue"; import { useRouter } from "vue-router"; @@ -15,9 +16,11 @@ import { STARTERS } from "./pageStarters"; const props = defineProps({ // Pre-filled address, e.g. the path of the 404 being looked at. slug: { type: String, default: "" }, - // Fixed leading part of the address, e.g. "shrines/" on /shrines. + // Fixed leading part of the address, e.g. "shrines/" for a new shrine. prefix: { type: String, default: "" }, starter: { type: String, default: "blank" }, + placeholder: { type: String, default: "address, e.g. shrines/evangelion" }, + submitLabel: { type: String, default: "Create page" }, }); const emit = defineEmits(["created"]); @@ -64,7 +67,7 @@ async function submit() {
Only admins can see this page - +

{{ error }}

diff --git a/vue/src/views/canvas/pageStarters.js b/vue/src/views/canvas/pageStarters.js index d548cc2..c9da0ee 100644 --- a/vue/src/views/canvas/pageStarters.js +++ b/vue/src/views/canvas/pageStarters.js @@ -4,62 +4,8 @@ * stores/boxes.js — without `page`, which the store adds. Everything is an * ordinary box afterwards: move it, edit it, delete it. */ -import { galleryHtml, imageHtml } from "@/views/home3/templates"; - -const escape = (s) => - s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]); - const html = (title, body, geom, extra = {}) => ({ kind: "html", title, html: body, ...geom, ...extra }); -function shrine(title) { - const t = escape(title); - return [ - html( - "Heading", - ` -
-

${t}

-

a shrine

-
`, - { x: 300, y: 20, w: 800, h: 160 }, - { framed: false }, - ), - html( - "Main image", - imageHtml("/img/memes/epic.jpeg"), - { x: 300, y: 200, w: 380, h: 380 }, - { framed: false }, - ), - html( - "About", - `

Why ${t}

-

What it is, and why it gets a shrine.

-

Favourite moments

-
    -
  • …
  • -
`, - { x: 700, y: 200, w: 400, h: 380 }, - ), - html( - "Gallery", - galleryHtml(["/img/memes/fire-woman.gif", "/img/memes/mix.gif", "/img/memes/lol.jpg"]), - { x: 300, y: 600, w: 800, h: 320 }, - ), - html( - "Quote", - ` -
“A line worth remembering.”
`, - { x: 300, y: 940, w: 800, h: 120 }, - ), - ].map((box, i) => ({ z: i + 1, ...box })); -} - function notes() { const note = (text, x, y) => html( @@ -82,6 +28,5 @@ function notes() { export const STARTERS = [ { id: "blank", label: "Blank", boxes: () => [] }, - { id: "shrine", label: "Shrine", boxes: shrine }, { id: "notes", label: "Notes board (admin-only notes)", boxes: notes }, ]; diff --git a/vue/src/views/home/shrines/Shrines.vue b/vue/src/views/home/shrines/Shrines.vue index 54cf1ff..8388dc4 100644 --- a/vue/src/views/home/shrines/Shrines.vue +++ b/vue/src/views/home/shrines/Shrines.vue @@ -1,10 +1,13 @@ @@ -391,7 +382,6 @@ function toggleEdit() { , so it is fixed to the window whatever * transform or stacking context the page puts around the canvas. */ -import { computed, ref, watch } from "vue"; +import { computed, onBeforeUnmount, ref, watch } from "vue"; import { useBoxesStore } from "@/stores/boxes"; import { tagFor, uploadFile } from "./upload"; import CodeEditor from "./CodeEditor.vue"; @@ -38,16 +40,33 @@ const draftHtml = ref(props.box.html ?? ""); const saving = ref(false); const dirty = computed(() => props.box.kind === "html" && draftHtml.value !== (props.box.html ?? "")); -// Switching to another box: drop this one's preview, start from the new -// box's saved html. +// Save the draft of box `id` if it differs from what is stored. Fire and +// forget: it runs as the editor moves on or unmounts, with nothing left to +// show progress in, so a failure is only reported through `error`. +function flush(id) { + const box = store.boxes.find((b) => b.id === id); + if (!box || box.kind !== "html" || draftHtml.value === (box.html ?? "")) return; + store.update(id, { html: draftHtml.value }).catch((err) => emit("error", err)); +} + +// Switching to another box: save the old one's draft, drop its preview, start +// from the new box's saved html. watch( () => props.box.id, - () => { + (_, oldId) => { + flush(oldId); emit("preview", null); draftHtml.value = props.box.html ?? ""; }, ); +// Deselecting, Done and ✕ all unmount the panel. +onBeforeUnmount(() => { + clearTimeout(previewTimer); + flush(props.box.id); + emit("preview", null); +}); + let previewTimer = null; watch(draftHtml, (html) => { clearTimeout(previewTimer); @@ -100,12 +119,8 @@ async function upload(event) { } function close() { - if (dirty.value && !confirm("Discard unsaved HTML changes?")) return; - emit("preview", null); emit("close"); } - -defineExpose({ close });