oficina / mapa Public

Clone
git clone https://amadan.net/oficina/mapa

Plain git — no account needed to clone.

Download

Download this file

1package mapa
2
3import (
4 "time"
5
6 "amadan.net/oficina/mapa/internal/mapa/locale"
7)
8
9// What History and the kicker say about an imported page (Notion
10// import spec §14.2). Both read the sealed record, at render, for people
11// who may open the page. A revision the import wrote reads as the
12// import's; the page's origin is kept by every later revision.
13
14// importedSummary is a version's summary when the import wrote it:
15// "Imported this from Notion · edited there 12 October 2026" for its
16// first revision, "Updated from Notion · …" for a later one, and a
17// rename's or a new look's own words with "(from Notion)" after them.
18func (history *pageHistory) importedSummary(index int,
19 plain string) (string, error) {
20 record, err := history.record(index)
21 if err != nil || !record.Imported {
22 return plain, err
23 }
24 switch history.verbs[history.rows[index].Revision] {
25 case VerbCreated:
26 return "Imported this from Notion" +
27 editedThere(history.viewer.Locale, record), nil
28 case VerbRenamed, VerbStyled:
29 // The look changed with no edit there: no "edited there" date,
30 // which would be the body's (Fable on phase 4, M2).
31 return plain + " (from Notion)", nil
32 }
33 return "Updated from Notion" +
34 editedThere(history.viewer.Locale, record), nil
35}
36
37// editedThere is " · edited there 12 October 2026", or "" when Notion
38// gave no time.
39func editedThere(dates *locale.Locale, record Record) string {
40 if day := notionDay(dates, record.Origin, false); day != "" {
41 return " · edited there " + day
42 }
43 return ""
44}
45
46// fromNotion is the kicker's note on an imported page, or "".
47func fromNotion(dates *locale.Locale, origin *Origin) string {
48 if origin == nil || origin.Source != "notion" {
49 return ""
50 }
51 if day := notionDay(dates, origin, true); day != "" {
52 return "From Notion, created there " + day
53 }
54 return "From Notion"
55}
56
57// notionDay is Notion's created or edited time as a day, "3 March
58// 2024" in dates's locale (level-up build note 85). Notion gives it in
59// UTC; the day is the day there.
60func notionDay(dates *locale.Locale, origin *Origin,
61 created bool) string {
62 if origin == nil {
63 return ""
64 }
65 raw := origin.Edited
66 if created {
67 raw = origin.Created
68 }
69 at, err := time.Parse(time.RFC3339, raw)
70 if err != nil {
71 return ""
72 }
73 return dates.Format("dateYear", at.UTC())
74}
75