WIP memoria: documents as documents; a bare front page; a one-line footer
Paul, 2026-10-30: no logo or cruft around the search box; documents on a page card, formatted by type. docrender.go draws the Notion connector's Markdown subset, property lists, tables, quotes and code around escaped text (links http(s) only, no images); the footer's egress statement sits in a <details> under one line.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+417
−69
internal/memoria/docrender.go+219 −0internal/memoria/docrender_test.go+57 −0internal/memoria/handlers.go+32 −17internal/memoria/static/memoria.css+61 −18internal/memoria/store.go+18 −14internal/memoria/templates/document.html+14 −10internal/memoria/templates/index.html+2 −8internal/memoria/templates/layout.html+10 −2tools/drive/main.go+4 −0
CI failed — run details
diff --git a/internal/memoria/docrender.go b/internal/memoria/docrender.go| new file mode 100644 |
| index 0000000..3e0a9df |
| --- /dev/null |
| +++ b/internal/memoria/docrender.go |
| @@ -0,0 +1,219 @@ |
| +package memoria |
| + |
| +import ( |
| + "html/template" |
| + "regexp" |
| + "strings" |
| +) |
| + |
| +// The document page renders a passage as a document rather than as one |
| +// preformatted paragraph (Paul, 2026-10-30: "de-jankifying the documents |
| +// themselves … formatted appropriately depending on type"). |
| +// |
| +// The input is what memoria stores: the Markdown subset the Notion |
| +// connector writes (notion/markdown.go — lists, numbered lists, to-dos, |
| +// quotes, code fences, dividers, tables), a database row's "Name: value" |
| +// property lines, and whatever someone pasted or uploaded. **Escaping |
| +// runs first and the structure is added around escaped text**, as |
| +// boldOnly does for an AI answer: no markup in a document can become |
| +// markup on the page, and the only element built from a document's own |
| +// characters is a link, and only to http(s). A remote image is never |
| +// loaded: an image in the source is a caption line by the time it is |
| +// stored (notion/markdown.go), and Markdown image syntax is text here. |
| + |
| +var ( |
| + listItem = regexp.MustCompile(`^(\s*)(?:[-*]|(\d+)\.)\s+(.*)$`) |
| + todoItem = regexp.MustCompile(`^\[( |x|X)\]\s+(.*)$`) |
| + property = regexp.MustCompile(`^([^:\n]{1,40}):\s+(.+)$`) |
| + bareURL = regexp.MustCompile(`https?://[^\s<>"'` + "`" + `]+`) |
| + tableRow = regexp.MustCompile(`^\s*\|.*\|\s*$`) |
| + tableRule = regexp.MustCompile(`^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$`) |
| + headingRow = regexp.MustCompile(`^(#{1,6})\s+(.*)$`) |
| +) |
| + |
| +// renderPassage turns one stored passage into the document page's HTML. |
| +func renderPassage(text string) template.HTML { |
| + lines := strings.Split(strings.ReplaceAll(text, "\r\n", "\n"), "\n") |
| + var b strings.Builder |
| + var para []string |
| + flush := func() { |
| + if len(para) == 0 { |
| + return |
| + } |
| + writeParagraph(&b, para) |
| + para = nil |
| + } |
| + for i := 0; i < len(lines); i++ { |
| + line := lines[i] |
| + trimmed := strings.TrimSpace(line) |
| + switch { |
| + case trimmed == "": |
| + flush() |
| + case strings.HasPrefix(trimmed, "```"): |
| + flush() |
| + var code []string |
| + for i++; i < len(lines) && !strings.HasPrefix(strings.TrimSpace(lines[i]), "```"); i++ { |
| + code = append(code, lines[i]) |
| + } |
| + b.WriteString("<pre rst-doc-code><code>" + template.HTMLEscapeString(strings.Join(code, "\n")) + "</code></pre>") |
| + case trimmed == "---" || trimmed == "***": |
| + flush() |
| + b.WriteString("<hr>") |
| + case headingRow.MatchString(trimmed): |
| + flush() |
| + m := headingRow.FindStringSubmatch(trimmed) |
| + b.WriteString("<h4 rst-doc-subhead>" + inline(m[2]) + "</h4>") |
| + case tableRow.MatchString(line): |
| + flush() |
| + var rows []string |
| + for ; i < len(lines) && tableRow.MatchString(lines[i]); i++ { |
| + rows = append(rows, lines[i]) |
| + } |
| + i-- |
| + writeTable(&b, rows) |
| + case listItem.MatchString(line): |
| + flush() |
| + var items []string |
| + for ; i < len(lines) && (listItem.MatchString(lines[i]) || strings.TrimSpace(lines[i]) == ""); i++ { |
| + if strings.TrimSpace(lines[i]) != "" { |
| + items = append(items, lines[i]) |
| + } |
| + } |
| + i-- |
| + writeList(&b, items) |
| + case strings.HasPrefix(trimmed, ">"): |
| + flush() |
| + var quote []string |
| + for ; i < len(lines) && strings.HasPrefix(strings.TrimSpace(lines[i]), ">"); i++ { |
| + quote = append(quote, inline(strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(lines[i]), ">")))) |
| + } |
| + i-- |
| + b.WriteString("<blockquote rst-doc-quote>" + strings.Join(quote, "<br>") + "</blockquote>") |
| + default: |
| + para = append(para, line) |
| + } |
| + } |
| + flush() |
| + return template.HTML(b.String()) |
| +} |
| + |
| +// writeParagraph writes one blank-line-separated block. Two or more lines |
| +// that are all "Name: value" — a database row's properties, or a pasted |
| +// contact block — are a property list; anything else is a paragraph whose |
| +// single line breaks are kept, because an address written over three |
| +// lines is three lines. |
| +func writeParagraph(b *strings.Builder, lines []string) { |
| + if len(lines) >= 2 { |
| + all := true |
| + for _, l := range lines { |
| + if !property.MatchString(strings.TrimSpace(l)) { |
| + all = false |
| + break |
| + } |
| + } |
| + if all { |
| + b.WriteString("<dl rst-doc-props>") |
| + for _, l := range lines { |
| + m := property.FindStringSubmatch(strings.TrimSpace(l)) |
| + b.WriteString("<dt>" + inline(m[1]) + "</dt><dd>" + inline(m[2]) + "</dd>") |
| + } |
| + b.WriteString("</dl>") |
| + return |
| + } |
| + } |
| + parts := make([]string, len(lines)) |
| + for i, l := range lines { |
| + parts[i] = inline(strings.TrimSpace(l)) |
| + } |
| + b.WriteString("<p>" + strings.Join(parts, "<br>") + "</p>") |
| +} |
| + |
| +// writeList writes a run of list items. Nesting is the source's own |
| +// indent, two spaces a level as notion/markdown.go writes it, carried as |
| +// rst-depth for the stylesheet rather than rebuilt as nested lists. |
| +func writeList(b *strings.Builder, items []string) { |
| + ordered := listItem.FindStringSubmatch(items[0])[2] != "" |
| + tag := "ul" |
| + if ordered { |
| + tag = "ol" |
| + } |
| + b.WriteString("<" + tag + " rst-doc-list>") |
| + for _, it := range items { |
| + m := listItem.FindStringSubmatch(it) |
| + depth := len(strings.ReplaceAll(m[1], "\t", " ")) / 2 |
| + if depth > 3 { |
| + depth = 3 |
| + } |
| + attr := "" |
| + if depth > 0 { |
| + attr = ` rst-depth="` + string(rune('0'+depth)) + `"` |
| + } |
| + body := m[3] |
| + if t := todoItem.FindStringSubmatch(body); t != nil { |
| + box := "☐" |
| + if t[1] != " " { |
| + box = "☑" |
| + } |
| + b.WriteString("<li" + attr + " rst-doc-todo>" + box + " " + inline(t[2]) + "</li>") |
| + continue |
| + } |
| + b.WriteString("<li" + attr + ">" + inline(body) + "</li>") |
| + } |
| + b.WriteString("</" + tag + ">") |
| +} |
| + |
| +// writeTable writes "| a | b |" rows. A Markdown rule row under the first |
| +// marks it as the header; Notion's rows carry no rule, so every row is a |
| +// body row there. |
| +func writeTable(b *strings.Builder, rows []string) { |
| + cells := func(row string) []string { |
| + row = strings.TrimSpace(row) |
| + row = strings.TrimSuffix(strings.TrimPrefix(row, "|"), "|") |
| + parts := strings.Split(row, "|") |
| + for i := range parts { |
| + parts[i] = strings.TrimSpace(parts[i]) |
| + } |
| + return parts |
| + } |
| + b.WriteString("<div rst-doc-table><table>") |
| + start := 0 |
| + if len(rows) > 1 && tableRule.MatchString(rows[1]) { |
| + b.WriteString("<thead><tr>") |
| + for _, c := range cells(rows[0]) { |
| + b.WriteString("<th>" + inline(c) + "</th>") |
| + } |
| + b.WriteString("</tr></thead>") |
| + start = 2 |
| + } |
| + b.WriteString("<tbody>") |
| + for _, r := range rows[start:] { |
| + b.WriteString("<tr>") |
| + for _, c := range cells(r) { |
| + b.WriteString("<td>" + inline(c) + "</td>") |
| + } |
| + b.WriteString("</tr>") |
| + } |
| + b.WriteString("</tbody></table></div>") |
| +} |
| + |
| +// inline renders a run of text: http(s) URLs become links, and between |
| +// them balanced **bold** is the only markup (boldOnly). The URL is taken |
| +// from the raw text and escaped into both the attribute and the label, so |
| +// nothing in it can close either. |
| +func inline(s string) string { |
| + var b strings.Builder |
| + last := 0 |
| + for _, m := range bareURL.FindAllStringIndex(s, -1) { |
| + end := m[1] |
| + // A sentence's own punctuation is not part of its link. |
| + for end > m[0] && strings.ContainsRune(".,;:!?)]'\"", rune(s[end-1])) { |
| + end-- |
| + } |
| + b.WriteString(string(boldOnly(s[last:m[0]]))) |
| + u := template.HTMLEscapeString(s[m[0]:end]) |
| + b.WriteString(`<a href="` + u + `" rel="noopener noreferrer nofollow">` + u + `</a>`) |
| + last = end |
| + } |
| + b.WriteString(string(boldOnly(s[last:]))) |
| + return b.String() |
| +} |
diff --git a/internal/memoria/docrender_test.go b/internal/memoria/docrender_test.go| new file mode 100644 |
| index 0000000..71797dd |
| --- /dev/null |
| +++ b/internal/memoria/docrender_test.go |
| @@ -0,0 +1,57 @@ |
| +package memoria |
| + |
| +import ( |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// The document page draws structure around escaped text, and nothing in a |
| +// document can become markup on the page. |
| +// |
| +// MUTATION-TESTED 2026-10-30, each reverted: inline() writing the text |
| +// before a link, or after the last one, unescaped → "<script"; code fences |
| +// unescaped → "<b>"; property values unescaped → "<i>". The URL pattern |
| +// stopping at quotes is tidiness, not a guard: with quotes admitted the |
| +// link is still escaped into its attribute, and that mutation stays green |
| +// for the right reason. |
| +func TestADocumentRendersAsADocumentAndNeverAsMarkup(t *testing.T) { |
| + // PRESENCE: the structures are drawn. |
| + for in, want := range map[string]string{ |
| + "Name: Bill\nEmail: bill@example.com": "<dl rst-doc-props><dt>Name</dt><dd>Bill</dd><dt>Email</dt><dd>bill@example.com</dd></dl>", |
| + "- one\n - two": `<ul rst-doc-list><li>one</li><li rst-depth="1">two</li></ul>`, |
| + "1. first\n2. second": "<ol rst-doc-list><li>first</li><li>second</li></ol>", |
| + "- [x] done": "<li rst-doc-todo>☑ done</li>", |
| + "> careful": "<blockquote rst-doc-quote>careful</blockquote>", |
| + "```\nx = 1\n```": "<pre rst-doc-code><code>x = 1</code></pre>", |
| + "| a | b |\n|---|---|\n| 1 | 2 |": "<thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>2</td></tr></tbody>", |
| + "See https://example.com/wiki.": `<a href="https://example.com/wiki" rel="noopener noreferrer nofollow">https://example.com/wiki</a>.`, |
| + "12 Main Street\nDublin 2": "<p>12 Main Street<br>Dublin 2</p>", |
| + "A **bold** claim": "<strong>bold</strong>", |
| + "Note: one line is a paragraph, not a list": "<p>Note: one line is a paragraph, not a list</p>", |
| + } { |
| + if got := string(renderPassage(in)); !strings.Contains(got, want) { |
| + t.Errorf("renderPassage(%q) = %q, want it to contain %q", in, got, want) |
| + } |
| + } |
| + // ABSENCE: nothing a document says becomes markup. |
| + for _, in := range []string{ |
| + "<script>alert(1)</script>", |
| + "<script>x</script> before https://example.com and after", |
| + "See https://example.com/\"onmouseover=alert(1) here", |
| + "javascript:alert(1)", |
| + "", |
| + "[click](javascript:alert(1))", |
| + "```\n<b>x</b>\n```", |
| + "Name: <i>Bill</i>\nRole: x", |
| + "| <img src=x> | b |", |
| + "- <svg onload=alert(1)>", |
| + "> <iframe>", |
| + } { |
| + got := string(renderPassage(in)) |
| + for _, bad := range []string{"<script", "<img", "<svg", "<iframe", "<b>", "<i>", `href="javascript`, "onmouseover=\"", `"onmouseover`} { |
| + if strings.Contains(got, bad) { |
| + t.Errorf("renderPassage(%q) = %q: %q reached the page", in, got, bad) |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/memoria/handlers.go b/internal/memoria/handlers.go| index 9281288..2138987 100644 |
| --- a/internal/memoria/handlers.go |
| +++ b/internal/memoria/handlers.go |
| @@ -1,6 +1,7 @@ |
| package memoria |
| import ( |
| + "html/template" |
| nativeauth "amadan.net/rastrillo/native/server" |
| "context" |
| "encoding/json" |
| @@ -167,9 +168,6 @@ type page struct { |
| FlashKind string |
| Results []Result |
| Documents []Summary |
| - // DocumentCount is the front page's "784 documents"; -1 when it could |
| - // not be read. |
| - DocumentCount int |
| Drop dropZone |
| // Notices is §6.5's loud withholding: what this page could not show |
| @@ -597,12 +595,6 @@ func (a *app) index(w http.ResponseWriter, r *http.Request) { |
| p := a.pageFor(r, f) |
| p.Query, p.Searched = q, q != "" |
| a.runSearch(r, &p) |
| - if !p.Searched { |
| - // The front page says how much there is to search, and links to |
| - // the list. A count that fails is not a count of zero: -1, and |
| - // the page says it is unavailable. |
| - p.DocumentCount = a.store.DocumentCount(r.Context()) |
| - } |
| // "Thanks — saved" after a correction or a rating returns here. |
| if kind, msg, ok := indexNotice.take(w, r); ok { |
| p.Flash, p.FlashKind = msg, kind |
| @@ -1165,8 +1157,13 @@ func displayName(c dropZone, s string) string { |
| // passage is one rendered passage of a document. |
| type passage struct { |
| Ordinal int |
| + // Heading is the passage's section, shown only where it changes: a |
| + // long section split into five passages is one heading, not five. |
| Heading string |
| - Text string |
| + // Depth is how deep that section is (h2 for a top-level one, h3 |
| + // below it), from the heading trail. |
| + Depth int |
| + HTML template.HTML |
| } |
| type documentPage struct { |
| @@ -1174,8 +1171,8 @@ type documentPage struct { |
| ID int64 |
| Title string |
| Source string |
| - Bytes int |
| - Revision int |
| + Path string |
| + Updated string |
| Passages []passage |
| } |
| @@ -1211,10 +1208,28 @@ func (a *app) showDocument(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| passages := make([]passage, 0, len(stored)) |
| + prev := "" |
| for _, p := range stored { |
| - passages = append(passages, passage{Ordinal: p.Ordinal, Heading: p.Heading, Text: p.Text}) |
| + pp := passage{Ordinal: p.Ordinal, HTML: renderPassage(p.Text)} |
| + if p.Heading != prev && p.Heading != "" { |
| + trail := strings.Split(p.Heading, " › ") |
| + pp.Heading = trail[len(trail)-1] |
| + pp.Depth = len(trail) |
| + // The document's title repeated as its first heading says |
| + // nothing the card's own title has not. |
| + if len(trail) == 1 && strings.EqualFold(pp.Heading, title) { |
| + pp.Heading = "" |
| + } |
| + } |
| + prev = p.Heading |
| + passages = append(passages, pp) |
| + } |
| + source, _, _, err := a.store.Meta(r.Context(), id) |
| + if err != nil { |
| + a.errorPage(w, r, http.StatusNotFound, kindDocument, "") |
| + return |
| } |
| - source, revision, nbytes, err := a.store.Meta(r.Context(), id) |
| + updated, path, err := a.store.Updated(r.Context(), id) |
| if err != nil { |
| a.errorPage(w, r, http.StatusNotFound, kindDocument, "") |
| return |
| @@ -1224,9 +1239,9 @@ func (a *app) showDocument(w http.ResponseWriter, r *http.Request) { |
| page: a.pageFor(r, frame{parts: []string{title}}), |
| ID: id, |
| Title: title, |
| - Source: source, |
| - Bytes: nbytes, |
| - Revision: revision, |
| + Source: sourceName(source), |
| + Path: path, |
| + Updated: updated.UTC().Format("2 Jan 2006"), |
| Passages: passages, |
| }) |
| } |
diff --git a/internal/memoria/static/memoria.css b/internal/memoria/static/memoria.css| index fb58583..5cf9572 100644 |
| --- a/internal/memoria/static/memoria.css |
| +++ b/internal/memoria/static/memoria.css |
| @@ -94,22 +94,10 @@ html { scrollbar-gutter: stable; } |
| [rst-suggest-fact-label] { color: var(--rst-text-muted); font-size: 0.875rem; } |
| [rst-suggest-all] { color: var(--rst-text-muted); font-size: 0.875rem; justify-content: space-between; } |
| -[rst-home] { padding-top: 18vh; } |
| +[rst-home] { padding-top: 24vh; min-height: 55vh; } |
| [rst-home] [rst-search] { margin-bottom: 0.75rem; } |
| -[rst-home-mark] { |
| - display: flex; |
| - align-items: center; |
| - justify-content: center; |
| - gap: 0.6rem; |
| - margin: 0 0 1.5rem; |
| - font-size: 2rem; |
| - font-weight: 650; |
| - letter-spacing: -0.02em; |
| -} |
| -[rst-home-note] { text-align: center; margin: 0 0 2.5rem; font-size: 0.875rem; } |
| @media (max-width: 640px) { |
| [rst-home] { padding-top: 6vh; } |
| - [rst-home-mark] { font-size: 1.6rem; margin-bottom: 1rem; } |
| } |
| [rst-section] { border-top: 1px solid var(--rst-line); margin-top: 2.5rem; padding-top: 1rem; } |
| @@ -429,11 +417,61 @@ html { scrollbar-gutter: stable; } |
| outline-offset: 3px; |
| } |
| -[rst-prose] { line-height: 1.6; } |
| -[rst-passage] { border-top: 1px solid var(--rst-line); padding: 0.8rem 0; } |
| -[rst-passage]:target { border-inline-start: 3px solid var(--rst-accent, var(--rst-text)); padding-inline-start: 0.7rem; } |
| -[rst-passage-heading] { font-size: 0.9375rem; margin: 0 0 0.4rem; text-transform: none; } |
| -[rst-passage] p { margin: 0; white-space: pre-wrap; } |
| +/* The document page (Paul, 2026-10-30): a document on a paper card. In |
| + light mode the card is white on the grey page; in dark it is the raised |
| + surface. Passages run on as one document; the one a citation points at |
| + is marked, in the margin, without moving the text. */ |
| +[rst-doc-meta] { font-size: 0.875rem; margin: 0 auto 0.75rem; max-width: 46rem; } |
| +[rst-doc-nav] { margin: 0 auto 0.4rem; max-width: 46rem; } |
| +[rst-paper] { |
| + background: var(--rst-surface); |
| + border: 1px solid var(--rst-line); |
| + border-radius: calc(var(--rst-radius) * 1.5); |
| + box-shadow: var(--rst-shadow-lift); |
| + margin: 0 auto 3rem; |
| + max-width: 46rem; |
| + padding: 2.75rem 3.25rem 3rem; |
| + line-height: 1.65; |
| +} |
| +[rst-doc-title] { font-size: 2rem; letter-spacing: -0.02em; margin: 0 0 1.5rem; } |
| +[rst-doc-heading] { margin: 1.75rem 0 0.5rem; } |
| +h2[rst-doc-heading] { font-size: 1.35rem; } |
| +h3[rst-doc-heading] { font-size: 1.1rem; } |
| +[rst-doc-subhead] { font-size: 1rem; margin: 1.25rem 0 0.4rem; } |
| +[rst-passage] { scroll-margin-top: 5rem; border-radius: 0.375rem; margin: 0 -0.75rem; padding: 0.15rem 0.75rem; } |
| +[rst-passage]:target { background: var(--rst-accent-soft); box-shadow: inset 3px 0 0 var(--rst-accent); } |
| +[rst-passage] p { margin: 0 0 0.9rem; } |
| +[rst-passage] a { overflow-wrap: anywhere; } |
| +[rst-doc-list] { margin: 0 0 0.9rem; padding-left: 1.4rem; } |
| +[rst-doc-list] li { margin: 0.15rem 0; } |
| +[rst-doc-list] li[rst-depth="1"] { margin-left: 1.4rem; } |
| +[rst-doc-list] li[rst-depth="2"] { margin-left: 2.8rem; } |
| +[rst-doc-list] li[rst-depth="3"] { margin-left: 4.2rem; } |
| +[rst-doc-list] li[rst-doc-todo] { list-style: none; margin-left: -1.4rem; } |
| +[rst-doc-props] { |
| + display: grid; |
| + grid-template-columns: minmax(7rem, max-content) 1fr; |
| + gap: 0.4rem 1.5rem; |
| + margin: 0 0 1.25rem; |
| + padding: 0.9rem 1rem; |
| + border: 1px solid var(--rst-line); |
| + border-radius: var(--rst-radius); |
| + background: var(--rst-surface-2); |
| +} |
| +[rst-doc-props] dt { color: var(--rst-text-muted); } |
| +[rst-doc-props] dd { margin: 0; } |
| +[rst-doc-quote] { border-inline-start: 3px solid var(--rst-line-strong); color: var(--rst-text-muted); margin: 0 0 0.9rem; padding: 0.1rem 0 0.1rem 1rem; } |
| +[rst-doc-code] { background: var(--rst-surface-2); border-radius: var(--rst-radius); font-size: 0.875rem; margin: 0 0 0.9rem; overflow-x: auto; padding: 0.75rem 1rem; } |
| +[rst-doc-table] { margin: 0 0 1rem; overflow-x: auto; } |
| +[rst-doc-table] table { border-collapse: collapse; font-size: 0.9375rem; } |
| +[rst-doc-table] th, [rst-doc-table] td { border: 1px solid var(--rst-line); padding: 0.35rem 0.6rem; text-align: left; vertical-align: top; } |
| +[rst-doc-table] th { background: var(--rst-surface-2); } |
| +@media (max-width: 640px) { |
| + [rst-paper] { padding: 1.5rem 1.25rem 2rem; border-radius: var(--rst-radius); } |
| + [rst-doc-title] { font-size: 1.6rem; } |
| + [rst-doc-props] { grid-template-columns: 1fr; gap: 0 0; } |
| + [rst-doc-props] dd { margin-bottom: 0.5rem; } |
| +} |
| [rst-breadcrumb] { margin-bottom: 0.75rem; } |
| @@ -650,3 +688,8 @@ html { scrollbar-gutter: stable; } |
| } |
| [rst-ai-cite] { font-size: 0.8125rem; text-decoration: none; } |
| [rst-ai-state] { font-size: 0.875rem; margin: 0; } |
| + |
| +/* The footer is one quiet line; the egress statement opens under it. */ |
| +[rst-foot-details] summary { cursor: pointer; font-size: 0.8125rem; list-style: none; } |
| +[rst-foot-details] summary::-webkit-details-marker { display: none; } |
| +[rst-foot-details] p { font-size: 0.8125rem; margin: 0.5rem 0 0; } |
diff --git a/internal/memoria/store.go b/internal/memoria/store.go| index 00dd020..aeb74f5 100644 |
| --- a/internal/memoria/store.go |
| +++ b/internal/memoria/store.go |
| @@ -972,20 +972,6 @@ func (s *Store) rule(ctx context.Context, asker suite.Subject, all []Result) Pag |
| return page |
| } |
| -// DocumentCount is how many documents are stored, for the front page, |
| -// and -1 when it cannot be read: a count that fails is not a count of |
| -// zero (AGENTS.md). |
| -func (s *Store) DocumentCount(ctx context.Context) int { |
| - var n int64 |
| - if err := s.db.G.WithContext(ctx).Model(&Document{}).Count(&n).Error; err != nil { |
| - if s.logger != nil { |
| - s.logger.Error("count documents", "err", err) |
| - } |
| - return -1 |
| - } |
| - return int(n) |
| -} |
| - |
| // Summaries lists every document, titles opened. |
| func (s *Store) Summaries(ctx context.Context) ([]Summary, error) { |
| var docs []Document |
| @@ -1077,6 +1063,24 @@ type Passage struct { |
| Text string |
| } |
| +// Updated returns when a document last changed and its ancestry in its |
| +// source ("Handbook › Onboarding"), for the line above the document page. |
| +func (s *Store) Updated(ctx context.Context, id int64) (time.Time, string, error) { |
| + var d Document |
| + if err := s.db.G.WithContext(ctx).Where("id = ?", id).First(&d).Error; err != nil { |
| + return time.Time{}, "", err |
| + } |
| + var path string |
| + if len(d.SealedPath) > 0 { |
| + p, err := s.sealer.Open(seal.PurposePath, d.SealedPath) |
| + if err != nil { |
| + return time.Time{}, "", err |
| + } |
| + path = string(p) |
| + } |
| + return d.UpdatedAt, path, nil |
| +} |
| + |
| // Meta returns a document's plaintext metadata. |
| func (s *Store) Meta(ctx context.Context, id int64) (source string, revision, bytes int, err error) { |
| var d Document |
diff --git a/internal/memoria/templates/document.html b/internal/memoria/templates/document.html| index e4fb353..488ed5a 100644 |
| --- a/internal/memoria/templates/document.html |
| +++ b/internal/memoria/templates/document.html |
| @@ -1,13 +1,17 @@ |
| +{{/* A document, presented as one (Paul, 2026-10-30): a paper card with |
| + its title, the source and date above it, and each passage rendered |
| + by docrender.go — lists, property lists, tables, quotes and code as |
| + what they are. Every passage keeps its #p{n} anchor, because every |
| + citation in memoria links to one, and the one a link points at is |
| + marked. The text is escaped before any structure is added. */}} |
| {{define "content"}} |
| -<nav rst-breadcrumb><a href="/">← Back to search</a></nav> |
| -<h1>{{.Title}}</h1> |
| -<p rst-muted>{{.Source}} · {{.Bytes}} bytes · revision {{.Revision}}</p> |
| -<article rst-prose> |
| -{{range .Passages}} |
| -<section id="p{{.Ordinal}}" rst-passage> |
| - {{if .Heading}}<h2 rst-passage-heading>{{.Heading}}</h2>{{end}} |
| - <p>{{.Text}}</p> |
| -</section> |
| -{{end}} |
| +<nav rst-breadcrumb rst-doc-nav><a href="/">← Search</a> · <a href="/documents">Documents</a></nav> |
| +<p rst-doc-meta rst-muted>{{.Source}}{{if .Path}} · {{.Path}}{{end}} · updated <time>{{.Updated}}</time></p> |
| +<article rst-paper> |
| + <h1 rst-doc-title>{{.Title}}</h1> |
| + {{range .Passages}} |
| + {{if .Heading}}{{if eq .Depth 1}}<h2 rst-doc-heading>{{.Heading}}</h2>{{else}}<h3 rst-doc-heading>{{.Heading}}</h3>{{end}}{{end}} |
| + <section id="p{{.Ordinal}}" rst-passage>{{.HTML}}</section> |
| + {{end}} |
| </article> |
| {{end}} |
diff --git a/internal/memoria/templates/index.html b/internal/memoria/templates/index.html| index 61ea53f..5eb26cb 100644 |
| --- a/internal/memoria/templates/index.html |
| +++ b/internal/memoria/templates/index.html |
| @@ -7,14 +7,11 @@ |
| border the polish audit found. */}} |
| {{/* The front page is a search box and nothing else (Paul, 2026-10-29: |
| "a bit more like Google with a simple search box in the middle"). |
| - With no query the box sits a third of the way down, under the |
| - wordmark, and live results grow below it without moving it. A page |
| + With no query the box sits a third of the way down and nothing else |
| + is on the page (Paul, 2026-10-30: no logo, no "cruft"). A page |
| loaded WITH a query — a link, a reload, a scriptless submit — is a |
| results page and starts at the top. The documents list is /documents. */}} |
| <div{{if not .Searched}} rst-home{{end}}> |
| -{{if not .Searched}} |
| - <p rst-home-mark><img src="{{asset "static/brand/icon.svg"}}" alt="" width="40" height="40"> Memoria</p> |
| -{{end}} |
| {{/* rst-suggest positions the typeahead under the box; search.js fills |
| rst-suggest-box from /suggest. Without the script it stays empty and |
| hidden, and Enter is the form's submit. */}} |
| @@ -26,9 +23,6 @@ |
| </form> |
| <div rst-suggest-box hidden></div> |
| </div> |
| -{{if not .Searched}} |
| - <p rst-home-note rst-muted>{{if lt .DocumentCount 0}}The document count is unavailable{{else}}<a href="/documents">{{.DocumentCount}} document{{if ne .DocumentCount 1}}s{{end}}</a>{{end}} · <a href="/add">Add content</a></p> |
| -{{end}} |
| {{/* The results region. search.js writes live results into it, and it |
| is here rather than around the {{if}} because an absent region has |
diff --git a/internal/memoria/templates/layout.html b/internal/memoria/templates/layout.html| index bfc383c..5732050 100644 |
| --- a/internal/memoria/templates/layout.html |
| +++ b/internal/memoria/templates/layout.html |
| @@ -88,7 +88,14 @@ |
| the one thing here that must survive a refresh: a region that |
| carried only the number would refresh a failure into a confident |
| zero, which is the failure shape this app has already had once. */}} |
| - <p rst-muted> |
| + {{/* One quiet line (Paul, 2026-10-30: "We don't really need the cruft |
| + around it"), and the whole egress statement one click away in a |
| + <details>, so it is still on every page, still in the markup the |
| + footer gates read, and works without a script. The summary itself |
| + names whether anything leaves. */}} |
| + <details rst-foot-details> |
| + <summary rst-muted>{{if .ModelOn}}🤖 AI is on · what is sent{{else}}No document leaves this instance{{end}}</summary> |
| + <p rst-muted> |
| <span rst-refresh="passages">{{if lt .Chunks 0}}The passage count is unavailable.{{else}}{{.Chunks}} passage{{if ne .Chunks 1}}s{{end}} indexed.{{end}}</span> |
| {{/* The egress claim, and it depends on the model switch (§8.9). With |
| AI off the strong sentence is true and is stated. With AI on it is |
| @@ -103,7 +110,8 @@ |
| while you type send nothing. No other document leaves this instance. |
| {{else}}Search is lexical only — no assistant, and <strong>no document ever |
| leaves this instance</strong>.{{end}} |
| - </p> |
| + </p> |
| + </details> |
| </footer>{{end}}{{end}} |
| </div> |
| </body> |
diff --git a/tools/drive/main.go b/tools/drive/main.go| index e6ed516..96ebe54 100644 |
| --- a/tools/drive/main.go |
| +++ b/tools/drive/main.go |
| @@ -125,6 +125,10 @@ func seedViaHTTP(h http.Handler, addr string) { |
| // §8.9: an address, which no recogniser can validate, so only the |
| // model layer can box it — rendered 🤖 and named, beside the |
| // validated eircode inside it. Search "office address". |
| + // The document page (2026-10-30): a database row's properties, |
| + // and a page carrying every structure docrender.go draws. |
| + {"Bill Horsman", "Membership Type: Member\nName: Bill Horsman\nPerson: Bill Horsman\nEmail: bill@example.com"}, |
| + {"Office handbook", "# Office handbook\n\nEverything you need for your **first week** in the office. The wiki is at https://example.com/wiki.\n\n## Getting in\n\nThe door code changes monthly.\n\n- Ring the bell marked Tito\n- Take the lift to the third floor\n - The stairs are behind the lift\n- [x] Collect your key fob\n- [ ] Book a desk\n\n> Please don't prop the fire door open.\n\n## Contacts\n\nOffice phone: +353 (0)1 547 7854\nReception: reception@example.com\nEircode: D02 X285\n\n| Who | Role |\n|---|---|\n| Paul | CEO |\n| Doc | CTO |\n\n## Wi-Fi\n\n```\nnetwork: tito-guest\npassword: see the fridge\n```\n\n1. Join the network\n2. Open any page\n3. Accept the terms"}, |
| // §8.12: an eircode with no word "eircode", "postcode" or |
| // "address" anywhere. Search "Eircode" or "postcode". |
| {"Where we are", "## Directions\n\nWe're at 1 Grand Canal Square, Dublin 2, A65 F4E2. Take the lift to the third floor."}, |