Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
This commit is contained in:
1 parent
288e6e94ac
commit
c1175d389f
699 files changed
+110197
-4117
No files matched your search
@@ -0,0 +1,150 @@
|
||||
// design-export renders the reviewed Japanese handbook; it never writes the DB.
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
xhtml "golang.org/x/net/html"
|
||||
"pageswiki/internal/render"
|
||||
)
|
||||
|
||||
const prefix = "/lab/pageswiki-dev"
|
||||
|
||||
var chapters = []string{
|
||||
"index", "principles", "address-storage", "campus-federation", "knowledge-city",
|
||||
"auth-permissions", "publication", "viewer-editor", "navigation-search",
|
||||
"scheduler-resources", "blog-diary", "extensions", "organizer", "tasks-tickets",
|
||||
"calendar-contacts", "feeds", "mail", "html-editor", "operations", "i18n",
|
||||
"roadmap", "decisions", "sources",
|
||||
}
|
||||
|
||||
type entry struct {
|
||||
Chapter string `json:"chapter"`
|
||||
Source string `json:"source"`
|
||||
File string `json:"file"`
|
||||
Path string `json:"path"`
|
||||
Language string `json:"language"`
|
||||
SourceSHA256 string `json:"source_sha256"`
|
||||
HTMLSHA256 string `json:"html_sha256"`
|
||||
}
|
||||
|
||||
func chapterPath(id string) string {
|
||||
if id == "index" {
|
||||
return prefix
|
||||
}
|
||||
return prefix + "/" + id
|
||||
}
|
||||
|
||||
func digest(b []byte) string {
|
||||
h := sha256.Sum256(b)
|
||||
return hex.EncodeToString(h[:])
|
||||
}
|
||||
|
||||
func validateLinks(body string) error {
|
||||
known := map[string]bool{prefix + "/": true}
|
||||
for _, id := range chapters {
|
||||
known[chapterPath(id)] = true
|
||||
}
|
||||
n, err := xhtml.Parse(strings.NewReader(body))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var visit func(*xhtml.Node) error
|
||||
visit = func(n *xhtml.Node) error {
|
||||
if n.Type == xhtml.ElementNode && n.Data == "a" {
|
||||
for _, a := range n.Attr {
|
||||
if a.Key != "href" {
|
||||
continue
|
||||
}
|
||||
p := strings.SplitN(a.Val, "#", 2)[0]
|
||||
if strings.HasPrefix(p, "/") && !known[p] {
|
||||
return fmt.Errorf("unmapped local documentation link: %s", a.Val)
|
||||
}
|
||||
}
|
||||
}
|
||||
for c := n.FirstChild; c != nil; c = c.NextSibling {
|
||||
if err := visit(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return visit(n)
|
||||
}
|
||||
|
||||
func export(src, dest string) error {
|
||||
if dest == "" {
|
||||
return fmt.Errorf("-out is required (use an empty staging directory)")
|
||||
}
|
||||
// Review/validate everything before producing any upload artifact.
|
||||
type document struct {
|
||||
entry entry
|
||||
body []byte
|
||||
}
|
||||
var docs []document
|
||||
for i, id := range chapters {
|
||||
file := filepath.Join(src, id+".md")
|
||||
md, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !strings.HasPrefix(string(md), "# ") {
|
||||
return fmt.Errorf("missing title: %s", file)
|
||||
}
|
||||
body := render.Markdown(string(md))
|
||||
if err := validateLinks(body); err != nil {
|
||||
return fmt.Errorf("%s: %w", file, err)
|
||||
}
|
||||
nav := `<nav aria-label="設計書の章移動"><a href="` + prefix + `">総目次</a>`
|
||||
if i > 0 {
|
||||
nav += ` · <a href="` + html.EscapeString(chapterPath(chapters[i-1])) + `">前の章</a>`
|
||||
}
|
||||
if i+1 < len(chapters) {
|
||||
nav += ` · <a href="` + html.EscapeString(chapterPath(chapters[i+1])) + `">次の章</a>`
|
||||
}
|
||||
nav += `</nav>`
|
||||
payload := []byte(nav + "\n" + body + "\n" + nav + "\n")
|
||||
docs = append(docs, document{entry{id, file, id + ".html", chapterPath(id), "ja", digest(md), digest(payload)}, payload})
|
||||
}
|
||||
if err := os.MkdirAll(dest, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
entries, err := os.ReadDir(dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(entries) != 0 {
|
||||
return fmt.Errorf("staging directory must be empty")
|
||||
}
|
||||
var manifest []entry
|
||||
for _, doc := range docs {
|
||||
if err := os.WriteFile(filepath.Join(dest, doc.entry.File), doc.body, 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
manifest = append(manifest, doc.entry)
|
||||
}
|
||||
b, err := json.MarshalIndent(manifest, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(filepath.Join(dest, "manifest.json"), append(b, '\n'), 0600)
|
||||
}
|
||||
|
||||
func main() {
|
||||
src := flag.String("src", "docs/design/ja", "reviewed Markdown source directory")
|
||||
out := flag.String("out", "", "empty staging directory; no database or network writes")
|
||||
flag.Parse()
|
||||
if err := export(*src, *out); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("Rendered %d Japanese chapters; manifest: %s\n", len(chapters), filepath.Join(*out, "manifest.json"))
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExportHandbook(t *testing.T) {
|
||||
dest := t.TempDir()
|
||||
if err := export("../../docs/design/ja", dest); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := os.ReadFile(filepath.Join(dest, "manifest.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var manifest []entry
|
||||
if err := json.Unmarshal(b, &manifest); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(manifest) != 23 {
|
||||
t.Fatalf("got %d chapters", len(manifest))
|
||||
}
|
||||
for _, e := range manifest {
|
||||
b, err := os.ReadFile(filepath.Join(dest, e.File))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if e.Language != "ja" || e.HTMLSHA256 != digest(b) || !strings.Contains(string(b), "<h1>") {
|
||||
t.Fatalf("invalid payload: %s", e.Chapter)
|
||||
}
|
||||
if err := validateLinks(string(b)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if e.Chapter == "address-storage" && !strings.Contains(string(b), "<table>") {
|
||||
t.Fatal("Markdown tables lost")
|
||||
}
|
||||
}
|
||||
if err := export("../../docs/design/ja", dest); err == nil {
|
||||
t.Fatal("must not overwrite staging artifacts")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnknownLink(t *testing.T) {
|
||||
if validateLinks(`<a href="/lab/pageswiki-dev/missing">x</a>`) == nil {
|
||||
t.Fatal("broken chapter link accepted")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user