Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Difference From version-0.0.11 To version-0.0.10
2021-04-05
| ||
15:59 | Increase version to 0.0.12-dev to begin next development cycle ... (check-in: 737632737f user: stern tags: trunk) | |
12:18 | Version 0.0.11 ... (check-in: 6db9ad537f user: stern tags: trunk, release, version-0.0.11) | |
2021-04-03
| ||
17:31 | Include license file and readme into zip-file for released software ... (check-in: ca6e7ae6d7 user: stern tags: trunk) | |
2021-02-26
| ||
11:53 | Increase version to 0.0.11-dev to begin next development cycle ... (check-in: d69e61d8eb user: stern tags: trunk) | |
11:14 | Version 0.0.10 ... (check-in: 5d9e4fc19e user: stern tags: trunk, release, version-0.0.10) | |
10:36 | WebUI: make meta line a little bit darker for better visibility ... (check-in: 09837eae5e user: stern tags: trunk) | |
Deleted .github/dependabot.yml.
|
| < < < < < < < < < < < < |
Changes to README.md.
|
| | < < < < < < < < | < < < < < < < < < | 1 2 3 | # zettelstore A storage and service for zettel notes. |
Changes to VERSION.
|
| | | 1 | 0.0.10 |
Changes to ast/ast.go.
︙ | ︙ | |||
18 19 20 21 22 23 24 | "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" ) // ZettelNode is the root node of the abstract syntax tree. // It is *not* part of the visitor pattern. type ZettelNode struct { | | < < | | > | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" ) // ZettelNode is the root node of the abstract syntax tree. // It is *not* part of the visitor pattern. type ZettelNode struct { Zettel domain.Zettel Zid id.Zid // Zettel identification. InhMeta *meta.Meta // Meta data of the zettel, with inherited values. Title InlineSlice // Zettel title is a sequence of inline nodes. Ast BlockSlice // Zettel abstract syntax tree is a sequence of block nodes. } // Node is the interface, all nodes must implement. type Node interface { Accept(v Visitor) } |
︙ | ︙ |
Changes to ast/block.go.
1 | //----------------------------------------------------------------------------- | | | 1 2 3 4 5 6 7 8 9 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- |
︙ | ︙ | |||
186 187 188 189 190 191 192 | func (tn *TableNode) blockNode() {} // Accept a visitor and visit the node. func (tn *TableNode) Accept(v Visitor) { v.VisitTable(tn) } //-------------------------------------------------------------------------- | | | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | func (tn *TableNode) blockNode() {} // Accept a visitor and visit the node. func (tn *TableNode) Accept(v Visitor) { v.VisitTable(tn) } //-------------------------------------------------------------------------- // BLOBNode contains just binary data that must be interpreted accordung to // a syntax. type BLOBNode struct { Title string Syntax string Blob []byte } func (bn *BLOBNode) blockNode() {} // Accept a visitor and visit the node. func (bn *BLOBNode) Accept(v Visitor) { v.VisitBLOB(bn) } |
Changes to ast/inline.go.
1 | //----------------------------------------------------------------------------- | | | 1 2 3 4 5 6 7 8 9 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- |
︙ | ︙ |
Changes to ast/traverser.go.
1 | //----------------------------------------------------------------------------- | | | 1 2 3 4 5 6 7 8 9 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- |
︙ | ︙ | |||
27 28 29 30 31 32 33 | // VisitVerbatim has nothing to traverse. func (t TopDownTraverser) VisitVerbatim(vn *VerbatimNode) { t.v.VisitVerbatim(vn) } // VisitRegion traverses the content and the additional text. func (t TopDownTraverser) VisitRegion(rn *RegionNode) { t.v.VisitRegion(rn) t.VisitBlockSlice(rn.Blocks) | | | | | | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | // VisitVerbatim has nothing to traverse. func (t TopDownTraverser) VisitVerbatim(vn *VerbatimNode) { t.v.VisitVerbatim(vn) } // VisitRegion traverses the content and the additional text. func (t TopDownTraverser) VisitRegion(rn *RegionNode) { t.v.VisitRegion(rn) t.VisitBlockSlice(rn.Blocks) t.visitInlineSlice(rn.Inlines) } // VisitHeading traverses the heading. func (t TopDownTraverser) VisitHeading(hn *HeadingNode) { t.v.VisitHeading(hn) t.visitInlineSlice(hn.Inlines) } // VisitHRule traverses nothing. func (t TopDownTraverser) VisitHRule(hn *HRuleNode) { t.v.VisitHRule(hn) } // VisitNestedList traverses all nested list elements. func (t TopDownTraverser) VisitNestedList(ln *NestedListNode) { t.v.VisitNestedList(ln) for _, item := range ln.Items { t.visitItemSlice(item) } } // VisitDescriptionList traverses all description terms and their associated // descriptions. func (t TopDownTraverser) VisitDescriptionList(dn *DescriptionListNode) { t.v.VisitDescriptionList(dn) for _, defs := range dn.Descriptions { t.visitInlineSlice(defs.Term) for _, descr := range defs.Descriptions { t.visitDescriptionSlice(descr) } } } // VisitPara traverses the inlines of a paragraph. func (t TopDownTraverser) VisitPara(pn *ParaNode) { t.v.VisitPara(pn) t.visitInlineSlice(pn.Inlines) } // VisitTable traverses all cells of the header and then row-wise all cells of // the table body. func (t TopDownTraverser) VisitTable(tn *TableNode) { t.v.VisitTable(tn) for _, col := range tn.Header { t.visitInlineSlice(col.Inlines) } for _, row := range tn.Rows { for _, col := range row { t.visitInlineSlice(col.Inlines) } } } // VisitBLOB traverses nothing. func (t TopDownTraverser) VisitBLOB(bn *BLOBNode) { t.v.VisitBLOB(bn) } |
︙ | ︙ | |||
97 98 99 100 101 102 103 | // VisitBreak traverses nothing. func (t TopDownTraverser) VisitBreak(bn *BreakNode) { t.v.VisitBreak(bn) } // VisitLink traverses the link text. func (t TopDownTraverser) VisitLink(ln *LinkNode) { t.v.VisitLink(ln) | | | | | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | // VisitBreak traverses nothing. func (t TopDownTraverser) VisitBreak(bn *BreakNode) { t.v.VisitBreak(bn) } // VisitLink traverses the link text. func (t TopDownTraverser) VisitLink(ln *LinkNode) { t.v.VisitLink(ln) t.visitInlineSlice(ln.Inlines) } // VisitImage traverses the image text. func (t TopDownTraverser) VisitImage(in *ImageNode) { t.v.VisitImage(in) t.visitInlineSlice(in.Inlines) } // VisitCite traverses the cite text. func (t TopDownTraverser) VisitCite(cn *CiteNode) { t.v.VisitCite(cn) t.visitInlineSlice(cn.Inlines) } // VisitFootnote traverses the footnote text. func (t TopDownTraverser) VisitFootnote(fn *FootnoteNode) { t.v.VisitFootnote(fn) t.visitInlineSlice(fn.Inlines) } // VisitMark traverses nothing. func (t TopDownTraverser) VisitMark(mn *MarkNode) { t.v.VisitMark(mn) } // VisitFormat traverses the formatted text. func (t TopDownTraverser) VisitFormat(fn *FormatNode) { t.v.VisitFormat(fn) t.visitInlineSlice(fn.Inlines) } // VisitLiteral traverses nothing. func (t TopDownTraverser) VisitLiteral(ln *LiteralNode) { t.v.VisitLiteral(ln) } // VisitBlockSlice traverses a block slice. func (t TopDownTraverser) VisitBlockSlice(bns BlockSlice) { |
︙ | ︙ | |||
149 150 151 152 153 154 155 | func (t TopDownTraverser) visitDescriptionSlice(dns DescriptionSlice) { for _, dn := range dns { dn.Accept(t) } } | < | | 149 150 151 152 153 154 155 156 157 158 159 160 | func (t TopDownTraverser) visitDescriptionSlice(dns DescriptionSlice) { for _, dn := range dns { dn.Accept(t) } } func (t TopDownTraverser) visitInlineSlice(ins InlineSlice) { for _, in := range ins { in.Accept(t) } } |
Changes to auth/policy/place.go.
︙ | ︙ | |||
14 15 16 17 18 19 20 | import ( "context" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" | < | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import ( "context" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" "zettelstore.de/z/web/session" ) // PlaceWithPolicy wraps the given place inside a policy place. func PlaceWithPolicy( place place.Place, simpleMode bool, |
︙ | ︙ | |||
90 91 92 93 94 95 96 | return nil, place.NewErrNotAllowed("GetMeta", user, zid) } func (pp *polPlace) FetchZids(ctx context.Context) (id.Set, error) { return nil, place.NewErrNotAllowed("fetch-zids", session.GetUser(ctx), id.Invalid) } | | > > > > > > > > | > > | > | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | return nil, place.NewErrNotAllowed("GetMeta", user, zid) } func (pp *polPlace) FetchZids(ctx context.Context) (id.Set, error) { return nil, place.NewErrNotAllowed("fetch-zids", session.GetUser(ctx), id.Invalid) } func (pp *polPlace) SelectMeta( ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) { user := session.GetUser(ctx) f = place.EnsureFilter(f) canRead := pp.policy.CanRead if sel := f.Select; sel != nil { f.Select = func(m *meta.Meta) bool { return canRead(user, m) && sel(m) } } else { f.Select = func(m *meta.Meta) bool { return canRead(user, m) } } result, err := pp.place.SelectMeta(ctx, f, s) return result, err } func (pp *polPlace) CanUpdateZettel(ctx context.Context, zettel domain.Zettel) bool { return pp.place.CanUpdateZettel(ctx, zettel) } func (pp *polPlace) UpdateZettel(ctx context.Context, zettel domain.Zettel) error { |
︙ | ︙ |
Changes to cmd/cmd_file.go.
1 | //----------------------------------------------------------------------------- | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- package cmd import ( "flag" "fmt" "io/ioutil" "os" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" |
︙ | ︙ | |||
36 37 38 39 40 41 42 | z := parser.ParseZettel( domain.Zettel{ Meta: meta, Content: domain.NewContent(inp.Src[inp.Pos:]), }, runtime.GetSyntax(meta), ) | | > > > | | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | z := parser.ParseZettel( domain.Zettel{ Meta: meta, Content: domain.NewContent(inp.Src[inp.Pos:]), }, runtime.GetSyntax(meta), ) enc := encoder.Create( format, &encoder.StringOption{Key: "lang", Value: runtime.GetLang(meta)}, ) if enc == nil { fmt.Fprintf(os.Stderr, "Unknown format %q\n", format) return 2, nil } _, err = enc.WriteZettel(os.Stdout, z, format != "raw") if err != nil { return 2, err } fmt.Println() return 0, nil } func getInput(args []string) (*meta.Meta, *input.Input, error) { if len(args) < 1 { src, err := ioutil.ReadAll(os.Stdin) if err != nil { return nil, nil, err } inp := input.NewInput(string(src)) m := meta.NewFromInput(id.New(true), inp) return m, inp, nil } src, err := ioutil.ReadFile(args[0]) if err != nil { return nil, nil, err } inp := input.NewInput(string(src)) m := meta.NewFromInput(id.New(true), inp) if len(args) > 1 { src, err := ioutil.ReadFile(args[1]) if err != nil { return nil, nil, err } inp = input.NewInput(string(src)) } return m, inp, nil } |
Changes to cmd/cmd_password.go.
︙ | ︙ | |||
11 12 13 14 15 16 17 | package cmd import ( "flag" "fmt" "os" | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | package cmd import ( "flag" "fmt" "os" "golang.org/x/crypto/ssh/terminal" "zettelstore.de/z/auth/cred" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" ) // ---------- Subcommand: password ------------------------------------------- |
︙ | ︙ | |||
64 65 66 67 68 69 70 | meta.KeyUserID, ident, ) return 0, nil } func getPassword(prompt string) (string, error) { fmt.Fprintf(os.Stderr, "%s: ", prompt) | | | 64 65 66 67 68 69 70 71 72 73 74 | meta.KeyUserID, ident, ) return 0, nil } func getPassword(prompt string) (string, error) { fmt.Fprintf(os.Stderr, "%s: ", prompt) password, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Fprintln(os.Stderr) return string(password), err } |
Changes to cmd/cmd_run.go.
︙ | ︙ | |||
82 83 84 85 86 87 88 | ucParseZettel := usecase.NewParseZettel(ucGetZettel) ucListMeta := usecase.NewListMeta(pp) ucListRoles := usecase.NewListRole(pp) ucListTags := usecase.NewListTags(pp) ucZettelContext := usecase.NewZettelContext(pp) router := router.NewRouter() | | | | | | | | | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | ucParseZettel := usecase.NewParseZettel(ucGetZettel) ucListMeta := usecase.NewListMeta(pp) ucListRoles := usecase.NewListRole(pp) ucListTags := usecase.NewListTags(pp) ucZettelContext := usecase.NewZettelContext(pp) router := router.NewRouter() router.Handle("/", webui.MakeGetRootHandler(pp)) router.AddListRoute('a', http.MethodGet, webui.MakeGetLoginHandler(te)) router.AddListRoute('a', http.MethodPost, adapter.MakePostLoginHandler( api.MakePostLoginHandlerAPI(ucAuthenticate), webui.MakePostLoginHandlerHTML(te, ucAuthenticate))) router.AddListRoute('a', http.MethodPut, api.MakeRenewAuthHandler()) router.AddZettelRoute('a', http.MethodGet, webui.MakeGetLogoutHandler()) if !readonlyMode { router.AddZettelRoute('b', http.MethodGet, webui.MakeGetRenameZettelHandler( te, ucGetMeta)) router.AddZettelRoute('b', http.MethodPost, webui.MakePostRenameZettelHandler( usecase.NewRenameZettel(pp))) router.AddZettelRoute('c', http.MethodGet, webui.MakeGetCopyZettelHandler( te, ucGetZettel, usecase.NewCopyZettel())) router.AddZettelRoute('c', http.MethodPost, webui.MakePostCreateZettelHandler( usecase.NewCreateZettel(pp))) router.AddZettelRoute('d', http.MethodGet, webui.MakeGetDeleteZettelHandler( te, ucGetZettel)) router.AddZettelRoute('d', http.MethodPost, webui.MakePostDeleteZettelHandler( usecase.NewDeleteZettel(pp))) router.AddZettelRoute('e', http.MethodGet, webui.MakeEditGetZettelHandler( te, ucGetZettel)) router.AddZettelRoute('e', http.MethodPost, webui.MakeEditSetZettelHandler( usecase.NewUpdateZettel(pp))) router.AddZettelRoute('f', http.MethodGet, webui.MakeGetFolgeZettelHandler( te, ucGetZettel, usecase.NewFolgeZettel())) router.AddZettelRoute('f', http.MethodPost, webui.MakePostCreateZettelHandler( usecase.NewCreateZettel(pp))) router.AddZettelRoute('g', http.MethodGet, webui.MakeGetNewZettelHandler( te, ucGetZettel, usecase.NewNewZettel())) router.AddZettelRoute('g', http.MethodPost, webui.MakePostCreateZettelHandler( usecase.NewCreateZettel(pp))) } router.AddListRoute('f', http.MethodGet, webui.MakeSearchHandler( te, usecase.NewSearch(pp), ucGetMeta, ucGetZettel)) router.AddListRoute('h', http.MethodGet, webui.MakeListHTMLMetaHandler( te, ucListMeta, ucListRoles, ucListTags)) router.AddZettelRoute('h', http.MethodGet, webui.MakeGetHTMLZettelHandler( te, ucParseZettel, ucGetMeta)) |
︙ | ︙ |
Changes to cmd/main.go.
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package cmd import ( "context" "flag" "fmt" "os" "strings" "zettelstore.de/z/config/runtime" "zettelstore.de/z/config/startup" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" | > | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package cmd import ( "context" "flag" "fmt" "io/ioutil" "os" "strings" "zettelstore.de/z/config/runtime" "zettelstore.de/z/config/startup" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" |
︙ | ︙ | |||
92 93 94 95 96 97 98 | func getConfig(fs *flag.FlagSet) (cfg *meta.Meta) { var configFile string if configFlag := fs.Lookup("c"); configFlag != nil { configFile = configFlag.Value.String() } else { configFile = defConfigfile } | | | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | func getConfig(fs *flag.FlagSet) (cfg *meta.Meta) { var configFile string if configFlag := fs.Lookup("c"); configFlag != nil { configFile = configFlag.Value.String() } else { configFile = defConfigfile } content, err := ioutil.ReadFile(configFile) if err != nil { cfg = meta.New(id.Invalid) } else { cfg = meta.NewFromInput(id.Invalid, input.NewInput(string(content))) } fs.Visit(func(flg *flag.Flag) { switch flg.Name { |
︙ | ︙ |
Changes to cmd/register.go.
︙ | ︙ | |||
22 23 24 25 26 27 28 | _ "zettelstore.de/z/parser/blob" // Allow to use BLOB parser. _ "zettelstore.de/z/parser/markdown" // Allow to use markdown parser. _ "zettelstore.de/z/parser/none" // Allow to use none parser. _ "zettelstore.de/z/parser/plain" // Allow to use plain parser. _ "zettelstore.de/z/parser/zettelmark" // Allow to use zettelmark parser. _ "zettelstore.de/z/place/constplace" // Allow to use global internal place. _ "zettelstore.de/z/place/dirplace" // Allow to use directory place. | < | 22 23 24 25 26 27 28 29 30 | _ "zettelstore.de/z/parser/blob" // Allow to use BLOB parser. _ "zettelstore.de/z/parser/markdown" // Allow to use markdown parser. _ "zettelstore.de/z/parser/none" // Allow to use none parser. _ "zettelstore.de/z/parser/plain" // Allow to use plain parser. _ "zettelstore.de/z/parser/zettelmark" // Allow to use zettelmark parser. _ "zettelstore.de/z/place/constplace" // Allow to use global internal place. _ "zettelstore.de/z/place/dirplace" // Allow to use directory place. _ "zettelstore.de/z/place/memplace" // Allow to use memory place. ) |
Changes to cmd/zettelstore/main.go.
1 | //----------------------------------------------------------------------------- | | > | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package main is the starting point for the zettelstore command. package main import ( "zettelstore.de/z/cmd" ) // Version variable. Will be filled by build process. var version string = "" func main() { cmd.Main("Zettelstore", version) } |
Changes to config/runtime/runtime.go.
︙ | ︙ | |||
39 40 41 42 43 44 45 | panic("configStock not set") } return configStock.GetMeta(id.ConfigurationZid) } // GetDefaultTitle returns the current value of the "default-title" key. func GetDefaultTitle() string { | < | | | < | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | panic("configStock not set") } return configStock.GetMeta(id.ConfigurationZid) } // GetDefaultTitle returns the current value of the "default-title" key. func GetDefaultTitle() string { if config := getConfigurationMeta(); config != nil { if title, ok := config.Get(meta.KeyDefaultTitle); ok { return title } } return "Untitled" } // GetDefaultSyntax returns the current value of the "default-syntax" key. func GetDefaultSyntax() string { |
︙ | ︙ | |||
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | func GetDefaultCopyright() string { if configStock != nil { if config := getConfigurationMeta(); config != nil { if copyright, ok := config.Get(meta.KeyDefaultCopyright); ok { return copyright } } } return "" } // GetDefaultLicense returns the current value of the "default-license" key. func GetDefaultLicense() string { if configStock != nil { | > | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | func GetDefaultCopyright() string { if configStock != nil { if config := getConfigurationMeta(); config != nil { if copyright, ok := config.Get(meta.KeyDefaultCopyright); ok { return copyright } } // TODO: get owner } return "" } // GetDefaultLicense returns the current value of the "default-license" key. func GetDefaultLicense() string { if configStock != nil { |
︙ | ︙ |
Changes to docs/manual/00000000000100.zettel.
1 2 3 4 5 6 7 8 | id: 00000000000100 title: Zettelstore Runtime Configuration role: configuration syntax: none default-copyright: (c) 2020-2021 by Detlef Stern <ds@zettelstore.de> default-license: EUPL-1.2-or-later default-visibility: public footer-html: <hr><p><a href="/home/doc/trunk/www/impri.wiki">Imprint / Privacy</a></p> | < < | 1 2 3 4 5 6 7 8 9 10 11 | id: 00000000000100 title: Zettelstore Runtime Configuration role: configuration syntax: none default-copyright: (c) 2020-2021 by Detlef Stern <ds@zettelstore.de> default-license: EUPL-1.2-or-later default-visibility: public footer-html: <hr><p><a href="/home/doc/trunk/www/impri.wiki">Imprint / Privacy</a></p> site-name: Zettelstore Manual visibility: owner |
Deleted docs/manual/00001000000000.zettel.
|
| < < < < < < < < < < < < < < < < < < < < < |
Changes to docs/manual/00001004011200.zettel.
1 2 | id: 00001004011200 title: Zettelstore places | < > | < < < < < > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | id: 00001004011200 title: Zettelstore places tags: #configuration #manual #zettelstore syntax: zmk role: manual A Zettelstore must store its zettel somehow and somewhere. In most cases you want to store your zettel as files in a directory. Under certain circumstances you may want to store your zettel in other places. An example are the [[predefined zettel|00001005090000]] that come with a Zettelstore. They are stored within the software itself. In another situation you may want to store your zettel volatilely, e.g. if you want to provide a sandbox for experimenting. To cope with these (and more) situations, you configure Zettelstore to use one or more places. This is done via the ''place-X-uri'' keys of the [[start-up configuration|00001004010000#place-X-uri]] (X is a number). Places are specified using special [[URIs|https://en.wikipedia.org/wiki/Uniform_Resource_Identifier]], somehow similar to web addresses. The following place URIs are supported: ; ''dir:\//DIR'' : Specifies a directory where zettel files are stored. ''DIR'' is the file path. Although it is possible to use relative file paths, such as ''./zettel'' (→ URI is ''dir:\//.zettel''), it is preferable to use absolute file paths, e.g. ''/home/user/zettel''. The directory must exist before starting the Zettelstore[^There is one exception: when Zettelstore is [[started without any parameter|00001004050000]], e.g. via double-clicking its icon, an directory called ''./zettel'' will be created.]. It is possible to [[configure|00001004011400]] a directory place. ; ''mem:'' : Stores all its zettel in volatile memory. If you stop the Zettelstore, all changes are lost. ; ''const:'' : Is a place of predefined, essential zettel. All places that you configure via the ''store-X-uri'' keys form a chain of places. If a zettel should be retrieved, a search starts in the place specified with the ''place-1-uri'' key, then ''place-2-uri'' and so on. If a zettel is created or changed, it is always stored in the place specified with the ''place-1-uri'' key. This allows to overwrite zettel from other places, e.g. the predefined zettel. If you did not configure the place of the predefined zettel (''const:'') they will automatically be appended as a last place. Otherwise Zettelstore will not work in certain situations. If you use the ''mem:'' place, where zettel are stored in volatile memory, it makes only sense if you configure it as ''place-1-uri''. Such a place will be empty when Zettelstore starts and only the place 1 will receive updates. You must make sure that your computer has enough RAM to store all zettel. |
Changes to docs/manual/00001006020000.zettel.
︙ | ︙ | |||
42 43 44 45 46 47 48 | If not given, the value ''default-license'' from the [[configuration zettel|00001004020000#default-license]] will be used. ; [!modified]''modified'' : Date and time when a zettel was modified through Zettelstore. If you edit a zettel with an editor software outside Zettelstore, you should set it manually to an appropriate value. This is a computed value. There is no need to set it via Zettelstore. | | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | If not given, the value ''default-license'' from the [[configuration zettel|00001004020000#default-license]] will be used. ; [!modified]''modified'' : Date and time when a zettel was modified through Zettelstore. If you edit a zettel with an editor software outside Zettelstore, you should set it manually to an appropriate value. This is a computed value. There is no need to set it via Zettelstore. ; [!new-role]''new-role'' : Used in a template zettel to specify the ''role'' of the new zettel. ; [!precursor]''precursor'' : References zettel for which this zettel is a ""Folgezettel"" / follow-up zettel. Basically the inverse of key [[''folge''|#folge]]. ; [!published]''published'' : This property contains the timestamp of the mast modification / creation of the zettel. If [[''modified''|#modified]]is set, it contains the same value. Otherwise, if the zettel identifier contains a valid timestamp, the identifier is used. |
︙ | ︙ |
Changes to docs/manual/00001006034000.zettel.
︙ | ︙ | |||
9 10 11 12 13 14 15 | A set is different to a list, as no duplicates are allowed. === Allowed values Every tag must must begin with the number sign character (""''#''"", ''U+0023''), followed by at least one printable character. Tags are separated by space characters. === Match operator | < | < < < < < < | 9 10 11 12 13 14 15 16 17 18 19 | A set is different to a list, as no duplicates are allowed. === Allowed values Every tag must must begin with the number sign character (""''#''"", ''U+0023''), followed by at least one printable character. Tags are separated by space characters. === Match operator A value matches a tag set value, if the first value is equal to at least one tag in the tag set. === Sorting Sorting is done by comparing the [[String|00001006033500]] values. |
Changes to docs/manual/00001006050000.zettel.
︙ | ︙ | |||
17 18 19 20 21 22 23 | In most cases the zettel identifier is the timestamp when the zettel was created. However, the Zettelstore software just checks for exactly 14 digits. Anybody is free to assign a ""non-timestamp"" identifier to a zettel, e.g. with a month part of ""35"" or with ""99"" as the last two digits. In fact, all identifiers of zettel initially provided by an empty Zettelstore begin with ""000000"", except the home zettel ''00010000000000''. | | | 17 18 19 20 21 22 23 24 25 26 27 | In most cases the zettel identifier is the timestamp when the zettel was created. However, the Zettelstore software just checks for exactly 14 digits. Anybody is free to assign a ""non-timestamp"" identifier to a zettel, e.g. with a month part of ""35"" or with ""99"" as the last two digits. In fact, all identifiers of zettel initially provided by an empty Zettelstore begin with ""000000"", except the home zettel ''00010000000000''. The identifiers of zettel if this manual have be chosen to begin with ""000010"". A zettel can have any identifier that contains 14 digits and that is not in use by another zettel managed by the same Zettelstore. |
Changes to docs/manual/00001010070200.zettel.
︙ | ︙ | |||
33 34 35 36 37 38 39 | The first zettel is the zettel that contains CSS for displaying the web interface. This is to ensure that the web interface looks nice even for not authenticated users. The other zettel is the zettel containing the [[version|00000000000001]] of the Zettelstore. Please note: if authentication is not enabled, every user has the same rights as the owner of a Zettelstore. This is also true, if the Zettelstore runs additionally in [[read-only mode|00001004010000#read-only-mode]]. In this case, the [[runtime configuration zettel|00001004020000]] is shown (its visibility is ""owner""). | | | 33 34 35 36 37 38 39 40 41 | The first zettel is the zettel that contains CSS for displaying the web interface. This is to ensure that the web interface looks nice even for not authenticated users. The other zettel is the zettel containing the [[version|00000000000001]] of the Zettelstore. Please note: if authentication is not enabled, every user has the same rights as the owner of a Zettelstore. This is also true, if the Zettelstore runs additionally in [[read-only mode|00001004010000#read-only-mode]]. In this case, the [[runtime configuration zettel|00001004020000]] is shown (its visibility is ""owner""). The [[start-up configuration|00001004010000]] is not shown, because the associated computed zettel with identifier ''00000000000099'' is stored with the visibility ""expert"". If you want to show such a zettel, you must set ''expert-mode'' to true. |
Changes to docs/manual/00001012051800.zettel.
︙ | ︙ | |||
15 16 17 18 19 20 21 | User-defined keys have the type ''e'' (string, possibly empty). For example, if you want to retrieve all zettel that contain the string ""API"" in its title, your request will be: ```sh # curl 'http://127.0.0.1:23123/z?title=API' {"list":[{"id":"00001012921000","url":"/z/00001012921000","meta":{"title":"API: JSON structure of an access token","tags":"#api #manual #reference #zettelstore","syntax":"zmk","role":"manual"}},{"id":"00001012920500","url":"/z/00001012920500","meta":{"title":"Formats available by the API","tags":"#api #manual #reference #zettelstore","syntax":"zmk","role":"manual"}},{"id":"00001012920000","url":"/z/00001012920000","meta":{"title":"Endpoints used by the API","tags":"#api #manual #reference #zettelstore","syntax":"zmk","role":"manual"}}, ... ``` | < < < < < < < < < < < < < | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | User-defined keys have the type ''e'' (string, possibly empty). For example, if you want to retrieve all zettel that contain the string ""API"" in its title, your request will be: ```sh # curl 'http://127.0.0.1:23123/z?title=API' {"list":[{"id":"00001012921000","url":"/z/00001012921000","meta":{"title":"API: JSON structure of an access token","tags":"#api #manual #reference #zettelstore","syntax":"zmk","role":"manual"}},{"id":"00001012920500","url":"/z/00001012920500","meta":{"title":"Formats available by the API","tags":"#api #manual #reference #zettelstore","syntax":"zmk","role":"manual"}},{"id":"00001012920000","url":"/z/00001012920000","meta":{"title":"Endpoints used by the API","tags":"#api #manual #reference #zettelstore","syntax":"zmk","role":"manual"}}, ... ``` If you are just interested in the zettel identifier, you should add the ""''_part''"" query parameter: ```sh # curl 'http://127.0.0.1:23123/z?title=API&_part=id' {"list":[{"id":"00001012921000","url":"/z/00001012921000"},{"id":"00001012920500","url":"/z/00001012920500"},{"id":"00001012920000","url":"/z/00001012920000"},{"id":"00001012051800","url":"/z/00001012051800"},{"id":"00001012051600","url":"/z/00001012051600"},{"id":"00001012051400","url":"/z/00001012051400"},{"id":"00001012051200","url":"/z/00001012051200"},{"id":"00001012050600","url":"/z/00001012050600"},{"id":"00001012050400","url":"/z/00001012050400"},{"id":"00001012050200","url":"/z/00001012050200"},{"id":"00001012000000","url":"/z/00001012000000"}]} ``` If you want only those zettel that additionally must contain the string ""JSON"", you have to add an additional query parameter: ```sh |
︙ | ︙ | |||
57 58 59 60 61 62 63 | The query parameter ""''_offset''"" allows to list not only the first elements, but to begin at a specific element: ```sh # curl 'http://192.168.17.7:23121/z?title=API&_part=id&_sort=id&_limit=2&_offset=1' {"list":[{"id":"00001012050200","url":"/z/00001012050200"},{"id":"00001012050400","url":"/z/00001012050400"}]} ``` === General filter | | | | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | The query parameter ""''_offset''"" allows to list not only the first elements, but to begin at a specific element: ```sh # curl 'http://192.168.17.7:23121/z?title=API&_part=id&_sort=id&_limit=2&_offset=1' {"list":[{"id":"00001012050200","url":"/z/00001012050200"},{"id":"00001012050400","url":"/z/00001012050400"}]} ``` === General filter The query parameter ""''_s''"" allows to provide a string, which will be searched for in all metadata. While searching, the [[type|00001006030000]] of each metadata key will be respected. You are allowed to specify this query parameter more than once. All results will be intersected, i.e. a zettel will be included into the list if both of the provided values match. This parameter loosely resembles the search box of the web user interface. |
Changes to docs/manual/00001012054000.zettel.
1 2 3 4 5 6 7 | id: 00001012054000 title: API: Retrieve zettel order within an existing zettel role: manual tags: #api #manual #zettelstore syntax: zmk Some zettel act as a ""table of contents"" for other zettel. | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | id: 00001012054000 title: API: Retrieve zettel order within an existing zettel role: manual tags: #api #manual #zettelstore syntax: zmk Some zettel act as a ""table of contents"" for other zettel. The [[Home zettel|00010000000000]] of this manual is one example, the [[general API description|00001012000000]] is another. Every zettel with a certain internal structure can act as the ""table of contents"" for others. What is a ""table of contents""? Basically, it is just a list of references to other zettel. To retrieve the ""table of contents"", the software looks at first level [[list items|00001007030200]]. If an item contains a valid reference to a zettel, this reference will be interpreted as an item in the table of contents. This applies only to first level list items (ordered or unordered list), but not to deeper levels. Only the first reference to a valid zettel is collected for the table of contents. Following references to zettel within such an list item are ignored. To retrieve the zettel order of an existing zettel, use the [[endpoint|00001012920000]] ''/o/{ID}''. ```` # curl http://127.0.0.1:23123/o/00010000000000 {"id":"00010000000000","url":"/z/00010000000000","meta":{...},"list":[{"id":"00001001000000","url":"/z/00001001000000","meta":{...}},{"id":"00001002000000","url":"/z/00001002000000","meta":{...}},{"id":"00001003000000","url":"/z/00001003000000","meta":{...}},{"id":"00001004000000","url":"/z/00001004000000","meta":{...}},...,{"id":"00001014000000","url":"/z/00001014000000","meta":{...}}]} ```` Formatted, this translates into:[^Metadata (key ''meta'') are hidden to make the overall structure easier to read.] ````json { "id": "00010000000000", "url": "/z/00010000000000", "order": [ { "id": "00001001000000", "url": "/z/00001001000000", "meta": {...} }, { |
︙ | ︙ |
Added docs/manual/00010000000000.zettel.
> > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | id: 00001000000000 title: Zettelstore Manual role: manual tags: #manual #zettelstore syntax: zmk * [[Introduction|00001001000000]] * [[Design goals|00001002000000]] * [[Installation|00001003000000]] * [[Configuration|00001004000000]] * [[Structure of Zettelstore|00001005000000]] * [[Layout of a zettel|00001006000000]] * [[Zettelmarkup|00001007000000]] * [[Other markup languages|00001008000000]] * [[Security|00001010000000]] * [[API|00001012000000]] * [[Web user interface|00001014000000]] * Troubleshooting * Frequently asked questions Licensed under the EUPL-1.2-or-later. |
Deleted docs/readmezip.txt.
|
| < < < < < < < < < < < < < < < < < < < < < |
Changes to domain/content.go.
1 | //----------------------------------------------------------------------------- | | > | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package domain provides domain specific types, constants, and functions. package domain import ( "unicode/utf8" ) // Content is just the uninterpreted content of a zettel. type Content string // NewContent creates a new content from a string. func NewContent(s string) Content { return Content(s) } |
︙ | ︙ |
Changes to domain/id/id.go.
︙ | ︙ | |||
31 32 33 34 35 36 37 | Invalid = Zid(0) // Invalid is a Zid that will never be valid ConfigurationZid = Zid(100) // WebUI HTML templates are in the range 10000..19999 BaseTemplateZid = Zid(10100) LoginTemplateZid = Zid(10200) ListTemplateZid = Zid(10300) | | < | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | Invalid = Zid(0) // Invalid is a Zid that will never be valid ConfigurationZid = Zid(100) // WebUI HTML templates are in the range 10000..19999 BaseTemplateZid = Zid(10100) LoginTemplateZid = Zid(10200) ListTemplateZid = Zid(10300) DetailTemplateZid = Zid(10401) InfoTemplateZid = Zid(10402) FormTemplateZid = Zid(10403) RenameTemplateZid = Zid(10404) DeleteTemplateZid = Zid(10405) ContextTemplateZid = Zid(10406) RolesTemplateZid = Zid(10500) TagsTemplateZid = Zid(10600) // WebUI CSS pages are in the range 20000..29999 BaseCSSZid = Zid(20001) // WebUI JS pages are in the range 30000..39999 // Range 90000...99999 is reserved for zettel templates |
︙ | ︙ |
Changes to domain/id/set.go.
︙ | ︙ | |||
40 41 42 43 44 45 46 | result := make(Set, c) for _, zid := range zids { result[zid] = true } return result } | | | < < < < < < < < < < < < < < < < < < < < | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | result := make(Set, c) for _, zid := range zids { result[zid] = true } return result } // Sort returns the set as a sorted slice of zettel identifier. func (s Set) Sort() Slice { if l := len(s); l > 0 { result := make(Slice, 0, l) for zid := range s { result = append(result, zid) } result.Sort() return result } return nil } |
Deleted domain/id/set_test.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Changes to domain/id/slice.go.
︙ | ︙ | |||
33 34 35 36 37 38 39 | return nil } result := make(Slice, len(zs)) copy(result, zs) return result } | < < < < < < < < < < < < < < < < < | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | return nil } result := make(Slice, len(zs)) copy(result, zs) return result } func (zs Slice) String() string { if len(zs) == 0 { return "" } var sb strings.Builder for i, zid := range zs { if i > 0 { sb.WriteByte(' ') } sb.WriteString(zid.String()) } return sb.String() } |
Changes to domain/id/slice_test.go.
︙ | ︙ | |||
14 15 16 17 18 19 20 | import ( "testing" "zettelstore.de/z/domain/id" ) | | | < | | < < < < < < < < < < < < < < < < < < < < < < < < < < | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import ( "testing" "zettelstore.de/z/domain/id" ) func TestSort(t *testing.T) { zs := id.Slice{9, 4, 6, 1, 7} zs.Sort() if zs[0] != 1 || zs[1] != 4 || zs[2] != 6 || zs[3] != 7 || zs[4] != 9 { t.Errorf("Slice.Sort did not work. Expected %v, got %v", id.Slice{1, 4, 6, 7, 9}, zs) } } func TestCopy(t *testing.T) { var orig id.Slice got := orig.Copy() if got != nil { t.Errorf("Nil copy resulted in %v", got) } orig = id.Slice{9, 4, 6, 1, 7} got = orig.Copy() if len(got) != len(orig) || got[0] != 9 || got[1] != 4 || got[2] != 6 || got[3] != 1 || got[4] != 7 { t.Errorf("Slice.Copy did not work. Expected %v, got %v", orig, got) } } func TestString(t *testing.T) { testcases := []struct { in id.Slice exp string }{ {nil, ""}, {id.Slice{}, ""}, {id.Slice{1}, "00000000000001"}, |
︙ | ︙ |
Changes to domain/meta/meta.go.
︙ | ︙ | |||
132 133 134 135 136 137 138 | KeyForward = registerKey("forward", TypeIDSet, usageProperty, "") KeyHomeZettel = registerKey("home-zettel", TypeID, usageUser, "") KeyLang = registerKey("lang", TypeWord, usageUser, "") KeyLicense = registerKey("license", TypeEmpty, usageUser, "") KeyListPageSize = registerKey("list-page-size", TypeNumber, usageUser, "") KeyMarkerExternal = registerKey("marker-external", TypeEmpty, usageUser, "") KeyModified = registerKey("modified", TypeTimestamp, usageComputed, "") | < | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | KeyForward = registerKey("forward", TypeIDSet, usageProperty, "") KeyHomeZettel = registerKey("home-zettel", TypeID, usageUser, "") KeyLang = registerKey("lang", TypeWord, usageUser, "") KeyLicense = registerKey("license", TypeEmpty, usageUser, "") KeyListPageSize = registerKey("list-page-size", TypeNumber, usageUser, "") KeyMarkerExternal = registerKey("marker-external", TypeEmpty, usageUser, "") KeyModified = registerKey("modified", TypeTimestamp, usageComputed, "") KeyPrecursor = registerKey("precursor", TypeIDSet, usageUser, KeyFolge) KeyPublished = registerKey("published", TypeTimestamp, usageProperty, "") KeyReadOnly = registerKey("read-only", TypeWord, usageUser, "") KeySiteName = registerKey("site-name", TypeString, usageUser, "") KeyURL = registerKey("url", TypeURL, usageUser, "") KeyUserID = registerKey("user-id", TypeWord, usageUser, "") KeyUserRole = registerKey("user-role", TypeWord, usageUser, "") |
︙ | ︙ |
Changes to domain/meta/meta_test.go.
︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | "strings" "testing" "zettelstore.de/z/domain/id" ) const testID = id.Zid(98765432101234) func TestKeyIsValid(t *testing.T) { validKeys := []string{"0", "a", "0-", "title", "title-----", strings.Repeat("r", 255)} for _, key := range validKeys { if !KeyIsValid(key) { t.Errorf("Key %q wrongly identified as invalid key", key) } | > > > > > > > > > > > > > > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | "strings" "testing" "zettelstore.de/z/domain/id" ) const testID = id.Zid(98765432101234) func newMeta(title string, tags []string, syntax string) *Meta { m := New(testID) if title != "" { m.Set(KeyTitle, title) } if tags != nil { m.Set(KeyTags, strings.Join(tags, " ")) } if syntax != "" { m.Set(KeySyntax, syntax) } return m } func TestKeyIsValid(t *testing.T) { validKeys := []string{"0", "a", "0-", "title", "title-----", strings.Repeat("r", 255)} for _, key := range validKeys { if !KeyIsValid(key) { t.Errorf("Key %q wrongly identified as invalid key", key) } |
︙ | ︙ |
Deleted encoder/encfun/encfun.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Changes to encoder/encoder.go.
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" ) // Encoder is an interface that allows to encode different parts of a zettel. type Encoder interface { WriteZettel(io.Writer, *ast.ZettelNode, bool) (int, error) WriteMeta(io.Writer, *meta.Meta) (int, error) WriteContent(io.Writer, *ast.ZettelNode) (int, error) WriteBlocks(io.Writer, ast.BlockSlice) (int, error) WriteInlines(io.Writer, ast.InlineSlice) (int, error) } // Some errors to signal when encoder methods are not implemented. var ( ErrNoWriteZettel = errors.New("method WriteZettel is not implemented") ErrNoWriteMeta = errors.New("method WriteMeta is not implemented") ErrNoWriteContent = errors.New("method WriteContent is not implemented") ErrNoWriteBlocks = errors.New("method WriteBlocks is not implemented") ErrNoWriteInlines = errors.New("method WriteInlines is not implemented") ) // Create builds a new encoder with the given options. | > > > > > > > | > > > > | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" ) // Encoder is an interface that allows to encode different parts of a zettel. type Encoder interface { SetOption(Option) WriteZettel(io.Writer, *ast.ZettelNode, bool) (int, error) WriteMeta(io.Writer, *meta.Meta) (int, error) WriteContent(io.Writer, *ast.ZettelNode) (int, error) WriteBlocks(io.Writer, ast.BlockSlice) (int, error) WriteInlines(io.Writer, ast.InlineSlice) (int, error) } // Some errors to signal when encoder methods are not implemented. var ( ErrNoWriteZettel = errors.New("method WriteZettel is not implemented") ErrNoWriteMeta = errors.New("method WriteMeta is not implemented") ErrNoWriteContent = errors.New("method WriteContent is not implemented") ErrNoWriteBlocks = errors.New("method WriteBlocks is not implemented") ErrNoWriteInlines = errors.New("method WriteInlines is not implemented") ) // Option allows to configure an encoder type Option interface { Name() string } // Create builds a new encoder with the given options. func Create(format string, options ...Option) Encoder { if info, ok := registry[format]; ok { enc := info.Create() for _, opt := range options { enc.SetOption(opt) } return enc } return nil } // Info stores some data about an encoder. type Info struct { Create func() Encoder Default bool } var registry = map[string]Info{} var defFormat string // Register the encoder for later retrieval. |
︙ | ︙ |
Deleted encoder/env.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Changes to encoder/htmlenc/block.go.
︙ | ︙ | |||
138 139 140 141 142 143 144 | v.b.WriteStrings("</h", strLvl, ">\n") } // VisitHRule writes HTML code for a horizontal rule: <hr>. func (v *visitor) VisitHRule(hn *ast.HRuleNode) { v.b.WriteString("<hr") v.visitAttributes(hn.Attrs) | | | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | v.b.WriteStrings("</h", strLvl, ">\n") } // VisitHRule writes HTML code for a horizontal rule: <hr>. func (v *visitor) VisitHRule(hn *ast.HRuleNode) { v.b.WriteString("<hr") v.visitAttributes(hn.Attrs) if v.xhtml { v.b.WriteString(" />\n") } else { v.b.WriteString(">\n") } } var listCode = map[ast.NestedListCode]string{ |
︙ | ︙ |
Changes to encoder/htmlenc/htmlenc.go.
1 | //----------------------------------------------------------------------------- | | > < < | > > > > > > > > > > > > > > > > > > > > | > > > > > | > > > > > | > > > > > > > > > > > > > > > > | > | < | | | < | | | | < < < < < < < < < < < < | < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package htmlenc encodes the abstract syntax tree into HTML5. package htmlenc import ( "fmt" "io" "strings" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" ) func init() { encoder.Register("html", encoder.Info{ Create: func() encoder.Encoder { return &htmlEncoder{} }, }) } type htmlEncoder struct { lang string // default language xhtml bool // use XHTML syntax instead of HTML syntax markerExternal string // Marker after link to (external) material. newWindow bool // open link in new window adaptLink func(*ast.LinkNode) ast.InlineNode adaptImage func(*ast.ImageNode) ast.InlineNode adaptCite func(*ast.CiteNode) ast.InlineNode ignoreMeta map[string]bool footnotes []*ast.FootnoteNode } func (he *htmlEncoder) SetOption(option encoder.Option) { switch opt := option.(type) { case *encoder.StringOption: switch opt.Key { case "lang": he.lang = opt.Value case meta.KeyMarkerExternal: he.markerExternal = opt.Value } case *encoder.BoolOption: switch opt.Key { case "newwindow": he.newWindow = opt.Value case "xhtml": he.xhtml = opt.Value } case *encoder.StringsOption: if opt.Key == "no-meta" { he.ignoreMeta = make(map[string]bool, len(opt.Value)) for _, v := range opt.Value { he.ignoreMeta[v] = true } } case *encoder.AdaptLinkOption: he.adaptLink = opt.Adapter case *encoder.AdaptImageOption: he.adaptImage = opt.Adapter case *encoder.AdaptCiteOption: he.adaptCite = opt.Adapter default: var name string if option != nil { name = option.Name() } fmt.Println("HESO", option, name) } } // WriteZettel encodes a full zettel as HTML5. func (he *htmlEncoder) WriteZettel( w io.Writer, zn *ast.ZettelNode, inhMeta bool) (int, error) { v := newVisitor(he, w) if !he.xhtml { v.b.WriteString("<!DOCTYPE html>\n") } v.b.WriteStrings("<html lang=\"", he.lang, "\">\n<head>\n<meta charset=\"utf-8\">\n") textEnc := encoder.Create("text") var sb strings.Builder textEnc.WriteInlines(&sb, zn.Title) v.b.WriteStrings("<title>", sb.String(), "</title>") if inhMeta { v.acceptMeta(zn.InhMeta, false) } else { v.acceptMeta(zn.Zettel.Meta, false) } v.b.WriteString("\n</head>\n<body>\n") v.acceptBlockSlice(zn.Ast) v.writeEndnotes() v.b.WriteString("</body>\n</html>") length, err := v.b.Flush() return length, err } // WriteMeta encodes meta data as HTML5. func (he *htmlEncoder) WriteMeta(w io.Writer, m *meta.Meta) (int, error) { v := newVisitor(he, w) v.acceptMeta(m, true) length, err := v.b.Flush() return length, err } func (he *htmlEncoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return he.WriteBlocks(w, zn.Ast) } // WriteBlocks encodes a block slice. func (he *htmlEncoder) WriteBlocks(w io.Writer, bs ast.BlockSlice) (int, error) { v := newVisitor(he, w) v.acceptBlockSlice(bs) v.writeEndnotes() length, err := v.b.Flush() return length, err } // WriteInlines writes an inline slice to the writer func (he *htmlEncoder) WriteInlines(w io.Writer, is ast.InlineSlice) (int, error) { v := newVisitor(he, w) v.acceptInlineSlice(is) length, err := v.b.Flush() return length, err } |
Changes to encoder/htmlenc/inline.go.
︙ | ︙ | |||
30 31 32 33 34 35 36 | v.b.WriteString("<span class=\"zettel-tag\">#") v.writeHTMLEscaped(tn.Tag) v.b.WriteString("</span>") } // VisitSpace emits a white space. func (v *visitor) VisitSpace(sn *ast.SpaceNode) { | | | > | > | | | > | < | < < < < < < < < < < < < < > | > | | | | > > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | v.b.WriteString("<span class=\"zettel-tag\">#") v.writeHTMLEscaped(tn.Tag) v.b.WriteString("</span>") } // VisitSpace emits a white space. func (v *visitor) VisitSpace(sn *ast.SpaceNode) { if v.inVerse || v.xhtml { v.b.WriteString(sn.Lexeme) } else { v.b.WriteByte(' ') } } // VisitBreak writes HTML code for line breaks. func (v *visitor) VisitBreak(bn *ast.BreakNode) { if bn.Hard { if v.xhtml { v.b.WriteString("<br />\n") } else { v.b.WriteString("<br>\n") } } else { v.b.WriteByte('\n') } } // VisitLink writes HTML code for links. func (v *visitor) VisitLink(ln *ast.LinkNode) { if adapt := v.enc.adaptLink; adapt != nil { n := adapt(ln) var ok bool if ln, ok = n.(*ast.LinkNode); !ok { n.Accept(v) return } } v.lang.push(ln.Attrs) defer v.lang.pop() switch ln.Ref.State { case ast.RefStateSelf, ast.RefStateFound, ast.RefStateHosted, ast.RefStateBased: v.writeAHref(ln.Ref, ln.Attrs, ln.Inlines) case ast.RefStateBroken: attrs := ln.Attrs.Clone() attrs = attrs.Set("class", "zs-broken") attrs = attrs.Set("title", "Zettel not found") // l10n v.writeAHref(ln.Ref, attrs, ln.Inlines) case ast.RefStateExternal: attrs := ln.Attrs.Clone() attrs = attrs.Set("class", "zs-external") if v.enc.newWindow { attrs = attrs.Set("target", "_blank").Set("rel", "noopener noreferrer") } v.writeAHref(ln.Ref, attrs, ln.Inlines) v.b.WriteString(v.enc.markerExternal) default: v.b.WriteString("<a href=\"") v.writeQuotedEscaped(ln.Ref.Value) v.b.WriteByte('"') v.visitAttributes(ln.Attrs) v.b.WriteByte('>') v.acceptInlineSlice(ln.Inlines) v.b.WriteString("</a>") } } func (v *visitor) writeAHref(ref *ast.Reference, attrs *ast.Attributes, ins ast.InlineSlice) { v.b.WriteString("<a href=\"") v.writeReference(ref) v.b.WriteByte('"') v.visitAttributes(attrs) v.b.WriteByte('>') v.acceptInlineSlice(ins) v.b.WriteString("</a>") } // VisitImage writes HTML code for images. func (v *visitor) VisitImage(in *ast.ImageNode) { if adapt := v.enc.adaptImage; adapt != nil { n := adapt(in) var ok bool if in, ok = n.(*ast.ImageNode); !ok { n.Accept(v) return } } v.lang.push(in.Attrs) defer v.lang.pop() if in.Ref == nil { v.b.WriteString("<img src=\"data:image/") switch in.Syntax { case "svg": |
︙ | ︙ | |||
139 140 141 142 143 144 145 | v.b.WriteString("<img src=\"") v.writeReference(in.Ref) } v.b.WriteString("\" alt=\"") v.acceptInlineSlice(in.Inlines) v.b.WriteByte('"') v.visitAttributes(in.Attrs) | | > | | | | | < < > > > | | | | > < < | | | < < < | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | v.b.WriteString("<img src=\"") v.writeReference(in.Ref) } v.b.WriteString("\" alt=\"") v.acceptInlineSlice(in.Inlines) v.b.WriteByte('"') v.visitAttributes(in.Attrs) if v.xhtml { v.b.WriteString(" />") } else { v.b.WriteByte('>') } } // VisitCite writes code for citations. func (v *visitor) VisitCite(cn *ast.CiteNode) { if adapt := v.enc.adaptCite; adapt != nil { n := adapt(cn) if n != cn { n.Accept(v) return } } v.lang.push(cn.Attrs) defer v.lang.pop() if cn != nil { v.b.WriteString(cn.Key) if len(cn.Inlines) > 0 { v.b.WriteString(", ") v.acceptInlineSlice(cn.Inlines) } } } // VisitFootnote write HTML code for a footnote. func (v *visitor) VisitFootnote(fn *ast.FootnoteNode) { v.lang.push(fn.Attrs) defer v.lang.pop() v.enc.footnotes = append(v.enc.footnotes, fn) n := strconv.Itoa(len(v.enc.footnotes)) v.b.WriteStrings("<sup id=\"fnref:", n, "\"><a href=\"#fn:", n, "\" class=\"zs-footnote-ref\" role=\"doc-noteref\">", n, "</a></sup>") // TODO: what to do with Attrs? } // VisitMark writes HTML code to mark a position. func (v *visitor) VisitMark(mn *ast.MarkNode) { if len(mn.Text) > 0 { v.b.WriteStrings("<a id=\"", mn.Text, "\"></a>") } } // VisitFormat write HTML code for formatting text. func (v *visitor) VisitFormat(fn *ast.FormatNode) { |
︙ | ︙ | |||
221 222 223 224 225 226 227 | case ast.FormatSub: code = "sub" case ast.FormatQuotation: code = "q" case ast.FormatSmall: code = "small" case ast.FormatSpan: | > | < < < < < < < < < < | 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | case ast.FormatSub: code = "sub" case ast.FormatQuotation: code = "q" case ast.FormatSmall: code = "small" case ast.FormatSpan: code = "span" attrs = processSpanAttributes(attrs) case ast.FormatMonospace: code = "span" attrs = attrs.Set("style", "font-family:monospace") case ast.FormatQuote: v.visitQuotes(fn) return default: panic(fmt.Sprintf("Unknown format code %v", fn.Code)) } v.b.WriteStrings("<", code) v.visitAttributes(attrs) v.b.WriteByte('>') v.acceptInlineSlice(fn.Inlines) v.b.WriteStrings("</", code, ">") } var langQuotes = map[string][2]string{ "en": {"“", "”"}, "de": {"„", "“"}, "fr": {"« ", " »"}, } |
︙ | ︙ |
Changes to encoder/htmlenc/visitor.go.
︙ | ︙ | |||
21 22 23 24 25 26 27 | "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" "zettelstore.de/z/strfun" ) // visitor writes the abstract syntax tree to an io.Writer. type visitor struct { | | | | | | | < < < < | | > | | | | > | > > > > > | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" "zettelstore.de/z/strfun" ) // visitor writes the abstract syntax tree to an io.Writer. type visitor struct { enc *htmlEncoder b encoder.BufWriter visibleSpace bool // Show space character in raw text inVerse bool // In verse block xhtml bool // copied from enc.xhtml lang langStack } func newVisitor(he *htmlEncoder, w io.Writer) *visitor { return &visitor{ enc: he, b: encoder.NewBufWriter(w), xhtml: he.xhtml, lang: newLangStack(he.lang), } } var mapMetaKey = map[string]string{ meta.KeyCopyright: "copyright", meta.KeyLicense: "license", } func (v *visitor) acceptMeta(m *meta.Meta, withTitle bool) { for i, pair := range m.Pairs(true) { if v.enc.ignoreMeta[pair.Key] { continue } if i == 0 { // "title" is number 0... if withTitle { // TODO: title value may contain zmk elements v.b.WriteStrings("<meta name=\"zs-", pair.Key, "\" content=\"") v.writeQuotedEscaped(pair.Value) v.b.WriteString("\">") } continue } if pair.Key == meta.KeyTags { v.writeTags(pair.Value) } else if key, ok := mapMetaKey[pair.Key]; ok { v.writeMeta("", key, pair.Value) } else { |
︙ | ︙ | |||
98 99 100 101 102 103 104 | func (v *visitor) acceptInlineSlice(ins ast.InlineSlice) { for _, in := range ins { in.Accept(v) } } func (v *visitor) writeEndnotes() { | < | | | | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | func (v *visitor) acceptInlineSlice(ins ast.InlineSlice) { for _, in := range ins { in.Accept(v) } } func (v *visitor) writeEndnotes() { if len(v.enc.footnotes) > 0 { v.b.WriteString("<ol class=\"zs-endnotes\">\n") for i := 0; i < len(v.enc.footnotes); i++ { // Do not use a range loop above, because a footnote may contain // a footnote. Therefore v.enc.footnote may grow during the loop. fn := v.enc.footnotes[i] n := strconv.Itoa(i + 1) v.b.WriteStrings("<li id=\"fn:", n, "\" role=\"doc-endnote\">") v.acceptInlineSlice(fn.Inlines) v.b.WriteStrings( " <a href=\"#fnref:", n, "\" class=\"zs-footnote-backref\" role=\"doc-backlink\">↩︎</a></li>\n") |
︙ | ︙ |
Changes to encoder/jsonenc/djsonenc.go.
︙ | ︙ | |||
16 17 18 19 20 21 22 | "io" "sort" "strconv" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" | < | > > > > > > > > | > > > > > > | > | | | > > > > | | | > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | "io" "sort" "strconv" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" ) func init() { encoder.Register("djson", encoder.Info{ Create: func() encoder.Encoder { return &jsonDetailEncoder{} }, }) } type jsonDetailEncoder struct { adaptLink func(*ast.LinkNode) ast.InlineNode adaptImage func(*ast.ImageNode) ast.InlineNode title ast.InlineSlice } // SetOption sets an option for the encoder func (je *jsonDetailEncoder) SetOption(option encoder.Option) { switch opt := option.(type) { case *encoder.TitleOption: je.title = opt.Inline case *encoder.AdaptLinkOption: je.adaptLink = opt.Adapter case *encoder.AdaptImageOption: je.adaptImage = opt.Adapter } } // WriteZettel writes the encoded zettel to the writer. func (je *jsonDetailEncoder) WriteZettel( w io.Writer, zn *ast.ZettelNode, inhMeta bool) (int, error) { v := newDetailVisitor(w, je) v.b.WriteString("{\"meta\":{\"title\":") v.acceptInlineSlice(zn.Title) if inhMeta { v.writeMeta(zn.InhMeta, false) } else { v.writeMeta(zn.Zettel.Meta, false) } v.b.WriteByte('}') v.b.WriteString(",\"content\":") v.acceptBlockSlice(zn.Ast) v.b.WriteByte('}') length, err := v.b.Flush() return length, err } // WriteMeta encodes meta data as JSON. func (je *jsonDetailEncoder) WriteMeta(w io.Writer, m *meta.Meta) (int, error) { v := newDetailVisitor(w, je) v.b.WriteByte('{') if je.title == nil { v.writeMeta(m, true) } else { v.b.WriteString("\"title\":") v.acceptInlineSlice(je.title) v.writeMeta(m, false) } v.b.WriteByte('}') length, err := v.b.Flush() return length, err } func (je *jsonDetailEncoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return je.WriteBlocks(w, zn.Ast) |
︙ | ︙ | |||
81 82 83 84 85 86 87 | length, err := v.b.Flush() return length, err } // detailVisitor writes the abstract syntax tree to an io.Writer. type detailVisitor struct { b encoder.BufWriter | | | | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | length, err := v.b.Flush() return length, err } // detailVisitor writes the abstract syntax tree to an io.Writer. type detailVisitor struct { b encoder.BufWriter enc *jsonDetailEncoder } func newDetailVisitor(w io.Writer, je *jsonDetailEncoder) *detailVisitor { return &detailVisitor{b: encoder.NewBufWriter(w), enc: je} } // VisitPara emits JSON code for a paragraph. func (v *detailVisitor) VisitPara(pn *ast.ParaNode) { v.writeNodeStart("Para") v.writeContentStart('i') v.acceptInlineSlice(pn.Inlines) |
︙ | ︙ | |||
313 314 315 316 317 318 319 | ast.RefStateHosted: "local", ast.RefStateBased: "based", ast.RefStateExternal: "external", } // VisitLink writes JSON code for links. func (v *detailVisitor) VisitLink(ln *ast.LinkNode) { | > | > | | | > > | > | | | > | 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | ast.RefStateHosted: "local", ast.RefStateBased: "based", ast.RefStateExternal: "external", } // VisitLink writes JSON code for links. func (v *detailVisitor) VisitLink(ln *ast.LinkNode) { if adapt := v.enc.adaptLink; adapt != nil { n := adapt(ln) var ok bool if ln, ok = n.(*ast.LinkNode); !ok { n.Accept(v) return } } v.writeNodeStart("Link") v.visitAttributes(ln.Attrs) v.writeContentStart('q') writeEscaped(&v.b, mapRefState[ln.Ref.State]) v.writeContentStart('s') writeEscaped(&v.b, ln.Ref.String()) v.writeContentStart('i') v.acceptInlineSlice(ln.Inlines) v.b.WriteByte('}') } // VisitImage writes JSON code for images. func (v *detailVisitor) VisitImage(in *ast.ImageNode) { if adapt := v.enc.adaptImage; adapt != nil { n := adapt(in) var ok bool if in, ok = n.(*ast.ImageNode); !ok { n.Accept(v) return } } v.writeNodeStart("Image") v.visitAttributes(in.Attrs) if in.Ref == nil { v.writeContentStart('j') v.b.WriteString("\"s\":") writeEscaped(&v.b, in.Syntax) |
︙ | ︙ | |||
538 539 540 541 542 543 544 | if b, ok := contentCode[code]; ok { v.b.Write(b) return } panic("Unknown content code " + strconv.Itoa(int(code))) } | | > | > > > > | > | 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | if b, ok := contentCode[code]; ok { v.b.Write(b) return } panic("Unknown content code " + strconv.Itoa(int(code))) } func (v *detailVisitor) writeMeta(m *meta.Meta, withTitle bool) { first := withTitle for _, p := range m.Pairs(true) { if p.Key == "title" && !withTitle { continue } if first { v.b.WriteByte('"') first = false } else { v.b.WriteString(",\"") } v.b.Write(Escape(p.Key)) v.b.WriteString("\":") if m.Type(p.Key).IsSet { v.writeSetValue(p.Value) } else { v.b.WriteByte('"') v.b.Write(Escape(p.Value)) |
︙ | ︙ |
Changes to encoder/jsonenc/jsonenc.go.
︙ | ︙ | |||
18 19 20 21 22 23 24 | "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" ) func init() { encoder.Register("json", encoder.Info{ | | > > > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" ) func init() { encoder.Register("json", encoder.Info{ Create: func() encoder.Encoder { return &jsonEncoder{} }, Default: true, }) } // jsonEncoder is just a stub. It is not implemented. The real implementation // is in file web/adapter/json.go type jsonEncoder struct{} // SetOption does nothing because this encoder does not recognize any option. func (je *jsonEncoder) SetOption(option encoder.Option) {} // WriteZettel writes the encoded zettel to the writer. func (je *jsonEncoder) WriteZettel( w io.Writer, zn *ast.ZettelNode, inhMeta bool) (int, error) { return 0, encoder.ErrNoWriteZettel } |
︙ | ︙ |
Changes to encoder/nativeenc/nativeenc.go.
︙ | ︙ | |||
16 17 18 19 20 21 22 | "io" "sort" "strconv" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" | < < | > > > > > > > | > > > > | | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | "io" "sort" "strconv" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" ) func init() { encoder.Register("native", encoder.Info{ Create: func() encoder.Encoder { return &nativeEncoder{} }, }) } type nativeEncoder struct { adaptLink func(*ast.LinkNode) ast.InlineNode adaptImage func(*ast.ImageNode) ast.InlineNode } // SetOption sets one option for this encoder. func (ne *nativeEncoder) SetOption(option encoder.Option) { switch opt := option.(type) { case *encoder.AdaptLinkOption: ne.adaptLink = opt.Adapter case *encoder.AdaptImageOption: ne.adaptImage = opt.Adapter } } // WriteZettel encodes the zettel to the writer. func (ne *nativeEncoder) WriteZettel( w io.Writer, zn *ast.ZettelNode, inhMeta bool) (int, error) { v := newVisitor(w, ne) v.b.WriteString("[Title ") v.acceptInlineSlice(zn.Title) v.b.WriteByte(']') if inhMeta { v.acceptMeta(zn.InhMeta, false) } else { v.acceptMeta(zn.Zettel.Meta, false) } v.b.WriteByte('\n') v.acceptBlockSlice(zn.Ast) length, err := v.b.Flush() return length, err } // WriteMeta encodes meta data as HTML5. func (ne *nativeEncoder) WriteMeta(w io.Writer, m *meta.Meta) (int, error) { v := newVisitor(w, ne) v.acceptMeta(m, true) length, err := v.b.Flush() return length, err } |
︙ | ︙ | |||
80 81 82 83 84 85 86 | return length, err } // visitor writes the abstract syntax tree to an io.Writer. type visitor struct { b encoder.BufWriter level int | | | | | | | < < < | > | | | | | | | | | | > | | | > | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | return length, err } // visitor writes the abstract syntax tree to an io.Writer. type visitor struct { b encoder.BufWriter level int enc *nativeEncoder } func newVisitor(w io.Writer, enc *nativeEncoder) *visitor { return &visitor{b: encoder.NewBufWriter(w), enc: enc} } var ( rawBackslash = []byte{'\\', '\\'} rawDoubleQuote = []byte{'\\', '"'} rawNewline = []byte{'\\', 'n'} ) func (v *visitor) acceptMeta(m *meta.Meta, withTitle bool) { if withTitle { v.b.WriteString("[Title \"") v.writeEscaped(m.GetDefault(meta.KeyTitle, "")) v.b.WriteString("\"]") } v.writeMetaString(m, meta.KeyRole, "Role") v.writeMetaList(m, meta.KeyTags, "Tags") v.writeMetaString(m, meta.KeySyntax, "Syntax") if pairs := m.PairsRest(true); len(pairs) > 0 { v.b.WriteString("\n[Header") first := true v.level++ for _, p := range pairs { if !first { v.b.WriteByte(',') } v.writeNewLine() v.b.WriteByte('[') v.b.WriteStrings(p.Key, " \"") v.writeEscaped(p.Value) v.b.WriteString("\"]") first = false } v.level-- v.b.WriteByte(']') } } func (v *visitor) writeMetaString(m *meta.Meta, key, native string) { if val, ok := m.Get(key); ok && len(val) > 0 { v.b.WriteStrings("\n[", native, " \"", val, "\"]") } } |
︙ | ︙ | |||
381 382 383 384 385 386 387 | ast.RefStateHosted: "LOCAL", ast.RefStateBased: "BASED", ast.RefStateExternal: "EXTERNAL", } // VisitLink writes native code for links. func (v *visitor) VisitLink(ln *ast.LinkNode) { | > | > | | | > > | > | | | > | 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | ast.RefStateHosted: "LOCAL", ast.RefStateBased: "BASED", ast.RefStateExternal: "EXTERNAL", } // VisitLink writes native code for links. func (v *visitor) VisitLink(ln *ast.LinkNode) { if adapt := v.enc.adaptLink; adapt != nil { n := adapt(ln) var ok bool if ln, ok = n.(*ast.LinkNode); !ok { n.Accept(v) return } } v.b.WriteString("Link") v.visitAttributes(ln.Attrs) v.b.WriteByte(' ') v.b.WriteString(mapRefState[ln.Ref.State]) v.b.WriteString(" \"") v.writeEscaped(ln.Ref.String()) v.b.WriteString("\" [") if !ln.OnlyRef { v.acceptInlineSlice(ln.Inlines) } v.b.WriteByte(']') } // VisitImage writes native code for images. func (v *visitor) VisitImage(in *ast.ImageNode) { if adapt := v.enc.adaptImage; adapt != nil { n := adapt(in) var ok bool if in, ok = n.(*ast.ImageNode); !ok { n.Accept(v) return } } v.b.WriteString("Image") v.visitAttributes(in.Attrs) if in.Ref == nil { v.b.WriteStrings(" {\"", in.Syntax, "\" \"") switch in.Syntax { case "svg": |
︙ | ︙ |
Added encoder/options.go.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package encoder provides a generic interface to encode the abstract syntax // tree into some text form. package encoder import ( "zettelstore.de/z/ast" ) // StringOption is an option with a string value type StringOption struct { Key string Value string } // Name returns the visible name of this option. func (so *StringOption) Name() string { return so.Key } // BoolOption is an option with a boolean value. type BoolOption struct { Key string Value bool } // Name returns the visible name of this option. func (bo *BoolOption) Name() string { return bo.Key } // TitleOption is an option to give the title as a AST inline slice type TitleOption struct { Inline ast.InlineSlice } // Name returns the visible name of this option. func (mo *TitleOption) Name() string { return "title" } // StringsOption is an option that have a sequence of strings as the value. type StringsOption struct { Key string Value []string } // Name returns the visible name of this option. func (so *StringsOption) Name() string { return so.Key } // AdaptLinkOption specifies a link adapter. type AdaptLinkOption struct { Adapter func(*ast.LinkNode) ast.InlineNode } // Name returns the visible name of this option. func (al *AdaptLinkOption) Name() string { return "AdaptLinkOption" } // AdaptImageOption specifies an image adapter. type AdaptImageOption struct { Adapter func(*ast.ImageNode) ast.InlineNode } // Name returns the visible name of this option. func (al *AdaptImageOption) Name() string { return "AdaptImageOption" } // AdaptCiteOption specifies a citation adapter. type AdaptCiteOption struct { Adapter func(*ast.CiteNode) ast.InlineNode } // Name returns the visible name of this option. func (al *AdaptCiteOption) Name() string { return "AdaptCiteOption" } |
Changes to encoder/rawenc/rawenc.go.
︙ | ︙ | |||
17 18 19 20 21 22 23 | "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" ) func init() { encoder.Register("raw", encoder.Info{ | | > > > | | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" ) func init() { encoder.Register("raw", encoder.Info{ Create: func() encoder.Encoder { return &rawEncoder{} }, }) } type rawEncoder struct{} // SetOption does nothing because this encoder does not recognize any option. func (re *rawEncoder) SetOption(option encoder.Option) {} // WriteZettel writes the encoded zettel to the writer. func (re *rawEncoder) WriteZettel( w io.Writer, zn *ast.ZettelNode, inhMeta bool) (int, error) { b := encoder.NewBufWriter(w) if inhMeta { zn.InhMeta.Write(&b, true) } else { zn.Zettel.Meta.Write(&b, true) } b.WriteByte('\n') b.WriteString(zn.Zettel.Content.AsString()) length, err := b.Flush() return length, err } // WriteMeta encodes meta data as HTML5. func (re *rawEncoder) WriteMeta(w io.Writer, m *meta.Meta) (int, error) { b := encoder.NewBufWriter(w) m.Write(&b, true) length, err := b.Flush() return length, err } func (re *rawEncoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { b := encoder.NewBufWriter(w) b.WriteString(zn.Zettel.Content.AsString()) length, err := b.Flush() return length, err } // WriteBlocks writes a block slice to the writer func (re *rawEncoder) WriteBlocks(w io.Writer, bs ast.BlockSlice) (int, error) { return 0, encoder.ErrNoWriteBlocks } // WriteInlines writes an inline slice to the writer func (re *rawEncoder) WriteInlines(w io.Writer, is ast.InlineSlice) (int, error) { return 0, encoder.ErrNoWriteInlines } |
Changes to encoder/textenc/textenc.go.
︙ | ︙ | |||
13 14 15 16 17 18 19 | import ( "io" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" | < | > > > | | > | | < < < < < < < < < < < < < < < < < | < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import ( "io" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" ) func init() { encoder.Register("text", encoder.Info{ Create: func() encoder.Encoder { return &textEncoder{} }, }) } type textEncoder struct{} // SetOption does nothing because this encoder does not recognize any option. func (te *textEncoder) SetOption(option encoder.Option) {} // WriteZettel does nothing. func (te *textEncoder) WriteZettel( w io.Writer, zn *ast.ZettelNode, inhMeta bool) (int, error) { v := newVisitor(w) if inhMeta { te.WriteMeta(&v.b, zn.InhMeta) } else { te.WriteMeta(&v.b, zn.Zettel.Meta) } v.acceptBlockSlice(zn.Ast) length, err := v.b.Flush() return length, err } // WriteMeta encodes meta data as text. func (te *textEncoder) WriteMeta(w io.Writer, m *meta.Meta) (int, error) { b := encoder.NewBufWriter(w) for _, pair := range m.Pairs(true) { b.WriteString(pair.Value) b.WriteByte('\n') } length, err := b.Flush() return length, err } func (te *textEncoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { |
︙ | ︙ |
Changes to encoder/zmkenc/zmkenc.go.
︙ | ︙ | |||
19 20 21 22 23 24 25 | "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" ) func init() { encoder.Register("zmk", encoder.Info{ | | > > > | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" ) func init() { encoder.Register("zmk", encoder.Info{ Create: func() encoder.Encoder { return &zmkEncoder{} }, }) } type zmkEncoder struct{} // SetOption does nothing because this encoder does not recognize any option. func (ze *zmkEncoder) SetOption(option encoder.Option) {} // WriteZettel writes the encoded zettel to the writer. func (ze *zmkEncoder) WriteZettel( w io.Writer, zn *ast.ZettelNode, inhMeta bool) (int, error) { v := newVisitor(w, ze) if inhMeta { zn.InhMeta.WriteAsHeader(&v.b, true) } else { zn.Zettel.Meta.WriteAsHeader(&v.b, true) } v.acceptBlockSlice(zn.Ast) length, err := v.b.Flush() return length, err } // WriteMeta encodes meta data as zmk. |
︙ | ︙ |
Changes to go.mod.
1 2 | module zettelstore.de/z | | | | < | | 1 2 3 4 5 6 7 8 9 10 11 | module zettelstore.de/z go 1.15 require ( github.com/fsnotify/fsnotify v1.4.9 github.com/pascaldekloe/jwt v1.10.0 github.com/yuin/goldmark v1.3.2 golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a golang.org/x/text v0.3.0 ) |
Changes to go.sum.
1 2 3 4 | github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/pascaldekloe/jwt v1.10.0 h1:ktcIUV4TPvh404R5dIBEnPCsSwj0sqi3/0+XafE5gJs= github.com/pascaldekloe/jwt v1.10.0/go.mod h1:TKhllgThT7TOP5rGr2zMLKEDZRAgJfBbtKyVeRsNB9A= | | | | | | | | | < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/pascaldekloe/jwt v1.10.0 h1:ktcIUV4TPvh404R5dIBEnPCsSwj0sqi3/0+XafE5gJs= github.com/pascaldekloe/jwt v1.10.0/go.mod h1:TKhllgThT7TOP5rGr2zMLKEDZRAgJfBbtKyVeRsNB9A= github.com/yuin/goldmark v1.3.2 h1:YjHC5TgyMmHpicTgEqDN0Q96Xo8K6tLXPnmNOHXCgs0= github.com/yuin/goldmark v1.3.2/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
Changes to index/index.go.
︙ | ︙ | |||
15 16 17 18 19 20 21 | "context" "io" "time" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" | | < < < < < < < < < < < < < < < | < | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | "context" "io" "time" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" ) // Enricher is used to update metadata by adding new properties. type Enricher interface { // Enrich computes additional properties and updates the given metadata. // It is typically called by zettel reading methods. Enrich(ctx context.Context, m *meta.Meta) } // NoEnrichContext will signal an enricher that nothing has to be done. // This is useful for an Indexer, but also for some place.Place calls, when // just the plain metadata is needed. func NoEnrichContext(ctx context.Context) context.Context { return context.WithValue(ctx, ctxNoEnrichKey, &ctxNoEnrichKey) } type ctxNoEnrichType struct{} var ctxNoEnrichKey ctxNoEnrichType // DoNotEnrich determines if the context is marked to not enrich metadata. func DoNotEnrich(ctx context.Context) bool { _, ok := ctx.Value(ctxNoEnrichKey).(*ctxNoEnrichType) return ok } // Port contains all the used functions to access zettel to be indexed. type Port interface { RegisterObserver(func(place.ChangeInfo)) FetchZids(context.Context) (id.Set, error) GetMeta(context.Context, id.Zid) (*meta.Meta, error) GetZettel(context.Context, id.Zid) (domain.Zettel, error) } // Indexer contains all the functions of an index. type Indexer interface { Enricher // Start the index. It will read all zettel and store index data for later retrieval. Start(Port) // Stop the index. No zettel are read any more, but the current index data // can stil be retrieved. Stop() |
︙ | ︙ | |||
101 102 103 104 105 106 107 | Store StoreStats } // Store all relevant zettel data. There may be multiple implementations, i.e. // memory-based, file-based, based on SQLite, ... type Store interface { Enricher | < | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | Store StoreStats } // Store all relevant zettel data. There may be multiple implementations, i.e. // memory-based, file-based, based on SQLite, ... type Store interface { Enricher // UpdateReferences for a specific zettel. // Returns set of zettel identifier that must also be checked for changes. UpdateReferences(context.Context, *ZettelIndex) id.Set // DeleteZettel removes index data for given zettel. // Returns set of zettel identifier that must also be checked for changes. |
︙ | ︙ | |||
125 126 127 128 129 130 131 | // StoreStats records statistics about the store. type StoreStats struct { // Zettel is the number of zettel managed by the indexer. Zettel int // Updates count the number of metadata updates. Updates uint64 | | < < < | 108 109 110 111 112 113 114 115 | // StoreStats records statistics about the store. type StoreStats struct { // Zettel is the number of zettel managed by the indexer. Zettel int // Updates count the number of metadata updates. Updates uint64 } |
Deleted index/indexer/collect.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Changes to index/indexer/indexer.go.
︙ | ︙ | |||
9 10 11 12 13 14 15 | //----------------------------------------------------------------------------- // Package indexer allows to search for metadata and content. package indexer import ( "context" | < < > > | < | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | //----------------------------------------------------------------------------- // Package indexer allows to search for metadata and content. package indexer import ( "context" "sync" "time" "zettelstore.de/z/ast" "zettelstore.de/z/collect" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" "zettelstore.de/z/index/memstore" "zettelstore.de/z/parser" "zettelstore.de/z/place" ) type indexer struct { store index.Store ar *anterooms ready chan struct{} // Signal a non-empty anteroom to background task done chan struct{} // Stop background task |
︙ | ︙ | |||
48 49 50 51 52 53 54 | return &indexer{ store: memstore.New(), ar: newAnterooms(10), ready: make(chan struct{}, 1), } } | | | | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | return &indexer{ store: memstore.New(), ar: newAnterooms(10), ready: make(chan struct{}, 1), } } func (idx *indexer) observer(ci place.ChangeInfo) { switch ci.Reason { case place.OnReload: idx.ar.Reset() case place.OnUpdate: idx.ar.Enqueue(ci.Zid, arUpdate) case place.OnDelete: idx.ar.Enqueue(ci.Zid, arDelete) default: return } select { case idx.ready <- struct{}{}: default: |
︙ | ︙ | |||
97 98 99 100 101 102 103 | // Enrich is called indirectly via indexer or enrichment is not requested // because of other reasons -> ignore this call, do not update meta data return } idx.store.Enrich(ctx, m) } | < < < < < < < < < < < < < < < < < < < | < < | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | // Enrich is called indirectly via indexer or enrichment is not requested // because of other reasons -> ignore this call, do not update meta data return } idx.store.Enrich(ctx, m) } func (idx *indexer) ReadStats(st *index.IndexerStats) { idx.mx.RLock() st.LastReload = idx.lastReload st.IndexesSinceReload = idx.sinceReload st.DurLastIndex = idx.durLastIndex idx.mx.RUnlock() idx.store.ReadStats(&st.Store) } type indexerPort interface { getMetaPort FetchZids(ctx context.Context) (id.Set, error) GetZettel(ctx context.Context, zid id.Zid) (domain.Zettel, error) } // indexer runs in the background and updates the index data structures. // This is the main service of the indexer. func (idx *indexer) indexer(p indexerPort) { // Something may panic. Ensure a running indexer. defer func() { if err := recover(); err != nil { go idx.indexer(p) } }() timerDuration := 15 * time.Second timer := time.NewTimer(timerDuration) ctx := index.NoEnrichContext(context.Background()) |
︙ | ︙ | |||
223 224 225 226 227 228 229 | type getMetaPort interface { GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) } func (idx *indexer) updateZettel(ctx context.Context, zettel domain.Zettel, p getMetaPort) { m := zettel.Meta | < < < < < < < < < | < < < < < | | < > | | | < < < < < > > > > > > > > > > > > > > > > > > > | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | type getMetaPort interface { GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) } func (idx *indexer) updateZettel(ctx context.Context, zettel domain.Zettel, p getMetaPort) { m := zettel.Meta zi := index.NewZettelIndex(m.Zid) for _, pair := range m.PairsRest(false) { descr := meta.GetDescription(pair.Key) if descr.IsComputed() { continue } switch descr.Type { case meta.TypeID: updateValue(ctx, descr.Inverse, pair.Value, p, zi) case meta.TypeIDSet: for _, val := range meta.ListFromValue(pair.Value) { updateValue(ctx, descr.Inverse, val, p, zi) } } } zn := parser.ParseZettel(zettel, "") refs := collect.References(zn) updateReferences(ctx, refs.Links, p, zi) updateReferences(ctx, refs.Images, p, zi) toCheck := idx.store.UpdateReferences(ctx, zi) idx.checkZettel(toCheck) } func updateValue(ctx context.Context, inverse string, value string, p getMetaPort, zi *index.ZettelIndex) { zid, err := id.Parse(value) if err != nil { return } if _, err := p.GetMeta(ctx, zid); err != nil { zi.AddDeadRef(zid) return } if inverse == "" { zi.AddBackRef(zid) return } zi.AddMetaRef(inverse, zid) } func updateReferences(ctx context.Context, refs []*ast.Reference, p getMetaPort, zi *index.ZettelIndex) { zrefs, _, _ := collect.DivideReferences(refs, false) for _, ref := range zrefs { updateReference(ctx, ref.URL.Path, p, zi) } } func updateReference(ctx context.Context, value string, p getMetaPort, zi *index.ZettelIndex) { zid, err := id.Parse(value) if err != nil { return } if _, err := p.GetMeta(ctx, zid); err != nil { zi.AddDeadRef(zid) return } zi.AddBackRef(zid) } func (idx *indexer) deleteZettel(zid id.Zid) { toCheck := idx.store.DeleteZettel(context.Background(), zid) idx.checkZettel(toCheck) } func (idx *indexer) checkZettel(s id.Set) { for zid := range s { idx.ar.Enqueue(zid, arUpdate) } } |
Changes to index/memstore/memstore.go.
︙ | ︙ | |||
11 12 13 14 15 16 17 | // Package memstore stored the index in main memory. package memstore import ( "context" "fmt" "io" | < < | | | | < | | < < < < < < < < < | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | // Package memstore stored the index in main memory. package memstore import ( "context" "fmt" "io" "sync" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" ) type metaRefs struct { forward id.Slice backward id.Slice } type zettelIndex struct { dead id.Slice forward id.Slice backward id.Slice meta map[string]metaRefs } func (zi *zettelIndex) isEmpty() bool { if len(zi.forward) > 0 || len(zi.backward) > 0 || len(zi.dead) > 0 { return false } return zi.meta == nil || len(zi.meta) == 0 } type memStore struct { mx sync.RWMutex idx map[id.Zid]*zettelIndex dead map[id.Zid]id.Slice // map dead refs where they occur // Stats updates uint64 } // New returns a new memory-based index store. func New() index.Store { return &memStore{ idx: make(map[id.Zid]*zettelIndex), dead: make(map[id.Zid]id.Slice), } } func (ms *memStore) Enrich(ctx context.Context, m *meta.Meta) { ms.mx.RLock() defer ms.mx.RUnlock() zi, ok := ms.idx[m.Zid] if !ok { return } var updated bool if len(zi.dead) > 0 { m.Set(meta.KeyDead, zi.dead.String()) updated = true } back := removeOtherMetaRefs(m, zi.backward.Copy()) |
︙ | ︙ | |||
101 102 103 104 105 106 107 | } } } if len(back) > 0 { m.Set(meta.KeyBack, back.String()) updated = true } | | < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | } } } if len(back) > 0 { m.Set(meta.KeyBack, back.String()) updated = true } if updated { ms.updates++ } } func removeOtherMetaRefs(m *meta.Meta, back id.Slice) id.Slice { for _, p := range m.PairsRest(false) { switch meta.Type(p.Key) { case meta.TypeID: if zid, err := id.Parse(p.Value); err == nil { |
︙ | ︙ | |||
182 183 184 185 186 187 188 | toCheck = id.NewSet(refs...) delete(ms.dead, zidx.Zid) } ms.updateDeadReferences(zidx, zi) ms.updateForwardBackwardReferences(zidx, zi) ms.updateMetadataReferences(zidx, zi) | < | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | toCheck = id.NewSet(refs...) delete(ms.dead, zidx.Zid) } ms.updateDeadReferences(zidx, zi) ms.updateForwardBackwardReferences(zidx, zi) ms.updateMetadataReferences(zidx, zi) // Check if zi must be inserted into ms.idx if !ziExist && !zi.isEmpty() { ms.idx[zidx.Zid] = zi } return toCheck |
︙ | ︙ | |||
251 252 253 254 255 256 257 | bmr.backward = addRef(bmr.backward, zidx.Zid) bzi.meta[key] = bmr } ms.removeInverseMeta(zidx.Zid, key, remRefs) } } | < < < < < < < < < < < < < < < < < < < < < < < < < < | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | bmr.backward = addRef(bmr.backward, zidx.Zid) bzi.meta[key] = bmr } ms.removeInverseMeta(zidx.Zid, key, remRefs) } } func (ms *memStore) getEntry(zid id.Zid) *zettelIndex { // Must only be called if ms.mx is write-locked! if zi, ok := ms.idx[zid]; ok { return zi } zi := &zettelIndex{} ms.idx[zid] = zi |
︙ | ︙ | |||
303 304 305 306 307 308 309 | ms.deleteDeadSources(zid, zi) toCheck := ms.deleteForwardBackward(zid, zi) if len(zi.meta) > 0 { for key, mrefs := range zi.meta { ms.removeInverseMeta(zid, key, mrefs.forward) } } | < | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | ms.deleteDeadSources(zid, zi) toCheck := ms.deleteForwardBackward(zid, zi) if len(zi.meta) > 0 { for key, mrefs := range zi.meta { ms.removeInverseMeta(zid, key, mrefs.forward) } } delete(ms.idx, zid) return toCheck } func (ms *memStore) deleteDeadSources(zid id.Zid, zi *zettelIndex) { // Must only be called if ms.mx is write-locked! for _, ref := range zi.dead { |
︙ | ︙ | |||
365 366 367 368 369 370 371 | if len(bzi.meta) == 0 { bzi.meta = nil } } } } | < < < < < < < < < < < < < < < < < | 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | if len(bzi.meta) == 0 { bzi.meta = nil } } } } func (ms *memStore) ReadStats(st *index.StoreStats) { ms.mx.RLock() st.Zettel = len(ms.idx) st.Updates = ms.updates ms.mx.RUnlock() } func (ms *memStore) Write(w io.Writer) { ms.mx.RLock() defer ms.mx.RUnlock() |
︙ | ︙ |
Deleted index/wordset.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted index/wordset_test.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Changes to index/zettel.go.
︙ | ︙ | |||
17 18 19 20 21 22 23 | // ZettelIndex contains all index data of a zettel. type ZettelIndex struct { Zid id.Zid // zid of the indexed zettel backrefs id.Set // set of back references metarefs map[string]id.Set // references to inverse keys deadrefs id.Set // set of dead references | < | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | // ZettelIndex contains all index data of a zettel. type ZettelIndex struct { Zid id.Zid // zid of the indexed zettel backrefs id.Set // set of back references metarefs map[string]id.Set // references to inverse keys deadrefs id.Set // set of dead references } // NewZettelIndex creates a new zettel index. func NewZettelIndex(zid id.Zid) *ZettelIndex { return &ZettelIndex{ Zid: zid, backrefs: id.NewSet(), |
︙ | ︙ | |||
51 52 53 54 55 56 57 | } // AddDeadRef adds a dead reference to a zettel. func (zi *ZettelIndex) AddDeadRef(zid id.Zid) { zi.deadrefs[zid] = true } | < < < | | | < < < | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | } // AddDeadRef adds a dead reference to a zettel. func (zi *ZettelIndex) AddDeadRef(zid id.Zid) { zi.deadrefs[zid] = true } // GetDeadRefs returns all dead references as a sorted list. func (zi *ZettelIndex) GetDeadRefs() id.Slice { return zi.deadrefs.Sort() } // GetBackRefs returns all back references as a sorted list. func (zi *ZettelIndex) GetBackRefs() id.Slice { return zi.backrefs.Sort() } // GetMetaRefs returns all meta references as a map of strings to a sorted list of references func (zi *ZettelIndex) GetMetaRefs() map[string]id.Slice { if len(zi.metarefs) == 0 { return nil } result := make(map[string]id.Slice, len(zi.metarefs)) for key, refs := range zi.metarefs { result[key] = refs.Sort() } return result } |
Changes to input/input.go.
1 | //----------------------------------------------------------------------------- | | | 1 2 3 4 5 6 7 8 9 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- |
︙ | ︙ | |||
73 74 75 76 77 78 79 | return ' ' } return r } return EOS } | < < < < < < < < < | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | return ' ' } return r } return EOS } // EatEOL transforms both "\r" and "\r\n" into "\n". func (inp *Input) EatEOL() { switch inp.Ch { case '\r': if inp.Peek() == '\n' { inp.Next() } |
︙ | ︙ | |||
126 127 128 129 130 131 132 133 134 | func (inp *Input) ScanEntity() (res string, success bool) { if inp.Ch != '&' { return "", false } pos := inp.Pos inp.Next() if inp.Ch == '#' { inp.Next() if inp.Ch == 'x' || inp.Ch == 'X' { | > < < < < < < | < | | | | < | | | | | | | | | | | | | | | | | | | | < | | | | < | | | | | | | | | | | | | | | | | | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | func (inp *Input) ScanEntity() (res string, success bool) { if inp.Ch != '&' { return "", false } pos := inp.Pos inp.Next() if inp.Ch == '#' { code := 0 inp.Next() if inp.Ch == 'x' || inp.Ch == 'X' { // Base 16 code inp.Next() if inp.Ch == ';' { return "", false } for { switch ch := inp.Ch; ch { case ';': inp.Next() return string(rune(code)), true case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': code = 16*code + int(ch-'0') case 'a', 'b', 'c', 'd', 'e', 'f': code = 16*code + int(ch-'a'+10) case 'A', 'B', 'C', 'D', 'E', 'F': code = 16*code + int(ch-'A'+10) default: return "", false } if code > unicode.MaxRune { return "", false } inp.Next() } } // Base 10 code if inp.Ch == ';' { return "", false } for { switch ch := inp.Ch; ch { case ';': inp.Next() return string(rune(code)), true case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': code = 10*code + int(ch-'0') default: return "", false } if code > unicode.MaxRune { return "", false } inp.Next() } } for { switch inp.Ch { case EOS, '\n', '\r': return "", false case ';': inp.Next() es := inp.Src[pos:inp.Pos] |
︙ | ︙ |
Changes to input/input_test.go.
1 | //----------------------------------------------------------------------------- | | | 1 2 3 4 5 6 7 8 9 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- |
︙ | ︙ |
Deleted parser/cleaner/cleaner.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Added parser/cleanup.go.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package parser provides a generic interface to a range of different parsers. package parser import ( "strconv" "strings" "zettelstore.de/z/ast" "zettelstore.de/z/encoder" "zettelstore.de/z/strfun" // Ensure that the text encoder is available _ "zettelstore.de/z/encoder/textenc" ) func cleanupBlockSlice(bs ast.BlockSlice) { cv := &cleanupVisitor{ textEnc: encoder.Create("text"), doMark: false, } t := ast.NewTopDownTraverser(cv) t.VisitBlockSlice(bs) if cv.hasMark { cv.doMark = true t.VisitBlockSlice(bs) } } type cleanupVisitor struct { textEnc encoder.Encoder ids map[string]ast.Node hasMark bool doMark bool } // VisitVerbatim does nothing. func (cv *cleanupVisitor) VisitVerbatim(vn *ast.VerbatimNode) {} // VisitRegion does nothing. func (cv *cleanupVisitor) VisitRegion(rn *ast.RegionNode) {} // VisitHeading calculates the heading slug. func (cv *cleanupVisitor) VisitHeading(hn *ast.HeadingNode) { if cv.doMark || hn == nil || hn.Inlines == nil { return } var sb strings.Builder _, err := cv.textEnc.WriteInlines(&sb, hn.Inlines) if err != nil { return } s := strfun.Slugify(sb.String()) if len(s) > 0 { hn.Slug = cv.addIdentifier(s, hn) } } // VisitHRule does nothing. func (cv *cleanupVisitor) VisitHRule(hn *ast.HRuleNode) {} // VisitList does nothing. func (cv *cleanupVisitor) VisitNestedList(ln *ast.NestedListNode) {} // VisitDescriptionList does nothing. func (cv *cleanupVisitor) VisitDescriptionList(dn *ast.DescriptionListNode) {} // VisitPara does nothing. func (cv *cleanupVisitor) VisitPara(pn *ast.ParaNode) {} // VisitTable does nothing. func (cv *cleanupVisitor) VisitTable(tn *ast.TableNode) {} // VisitBLOB does nothing. func (cv *cleanupVisitor) VisitBLOB(bn *ast.BLOBNode) {} // VisitText does nothing. func (cv *cleanupVisitor) VisitText(tn *ast.TextNode) {} // VisitTag does nothing. func (cv *cleanupVisitor) VisitTag(tn *ast.TagNode) {} // VisitSpace does nothing. func (cv *cleanupVisitor) VisitSpace(sn *ast.SpaceNode) {} // VisitBreak does nothing. func (cv *cleanupVisitor) VisitBreak(bn *ast.BreakNode) {} // VisitLink collects the given link as a reference. func (cv *cleanupVisitor) VisitLink(ln *ast.LinkNode) {} // VisitImage collects the image links as a reference. func (cv *cleanupVisitor) VisitImage(in *ast.ImageNode) {} // VisitCite does nothing. func (cv *cleanupVisitor) VisitCite(cn *ast.CiteNode) {} // VisitFootnote does nothing. func (cv *cleanupVisitor) VisitFootnote(fn *ast.FootnoteNode) {} // VisitMark checks for duplicate marks and changes them. func (cv *cleanupVisitor) VisitMark(mn *ast.MarkNode) { if mn == nil { return } if !cv.doMark { cv.hasMark = true return } if mn.Text == "" { mn.Text = cv.addIdentifier("*", mn) return } mn.Text = cv.addIdentifier(mn.Text, mn) } // VisitFormat does nothing. func (cv *cleanupVisitor) VisitFormat(fn *ast.FormatNode) {} // VisitLiteral does nothing. func (cv *cleanupVisitor) VisitLiteral(ln *ast.LiteralNode) {} func (cv *cleanupVisitor) addIdentifier(id string, node ast.Node) string { if cv.ids == nil { cv.ids = map[string]ast.Node{id: node} return id } if n, ok := cv.ids[id]; ok && n != node { prefix := id + "-" for count := 1; ; count++ { newID := prefix + strconv.Itoa(count) if n, ok := cv.ids[newID]; !ok || n == node { cv.ids[newID] = node return newID } } } cv.ids[id] = node return id } |
Changes to parser/markdown/markdown.go.
︙ | ︙ | |||
46 47 48 49 50 51 52 | panic("markdown.parseInline not yet implemented") } func parseMarkdown(inp *input.Input) *mdP { source := []byte(inp.Src[inp.Pos:]) parser := gm.DefaultParser() node := parser.Parse(gmText.NewReader(source)) | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | panic("markdown.parseInline not yet implemented") } func parseMarkdown(inp *input.Input) *mdP { source := []byte(inp.Src[inp.Pos:]) parser := gm.DefaultParser() node := parser.Parse(gmText.NewReader(source)) textEnc := encoder.Create("text") return &mdP{source: source, docNode: node, textEnc: textEnc} } type mdP struct { source []byte docNode gmAst.Node textEnc encoder.Encoder |
︙ | ︙ | |||
313 314 315 316 317 318 319 | result = append(result, &ast.SpaceNode{Lexeme: text[lastPos:]}) default: panic(fmt.Sprintf("Unexpected state %v", state)) } return result } | < < < < < < < < < > > > | > > > > | | | > | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | result = append(result, &ast.SpaceNode{Lexeme: text[lastPos:]}) default: panic(fmt.Sprintf("Unexpected state %v", state)) } return result } // cleanText removes backslashes from TextNodes and expands entities func cleanText(text string, cleanBS bool) string { if text == "" { return "" } lastPos := 0 var sb strings.Builder for pos, ch := range text { if pos < lastPos { continue } if ch == '&' { inp := input.NewInput(text[pos:]) if s, ok := inp.ScanEntity(); ok { sb.WriteString(text[lastPos:pos]) sb.WriteString(s) lastPos = pos + inp.Pos } continue } if cleanBS && ch == '\\' && pos < len(text)-1 { switch b := text[pos+1]; b { case '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~': sb.WriteString(text[lastPos:pos]) sb.WriteByte(b) lastPos = pos + 2 } } } if lastPos == 0 { return text } if lastPos < len(text) { sb.WriteString(text[lastPos:]) |
︙ | ︙ |
Changes to parser/parser.go.
︙ | ︙ | |||
15 16 17 18 19 20 21 | "log" "zettelstore.de/z/ast" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain" "zettelstore.de/z/domain/meta" "zettelstore.de/z/input" | < | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | "log" "zettelstore.de/z/ast" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain" "zettelstore.de/z/domain/meta" "zettelstore.de/z/input" ) // Info describes a single parser. // // Before ParseBlocks() or ParseInlines() is called, ensure the input stream to // be valid. This can ce achieved on calling inp.Next() after the input stream // was created. |
︙ | ︙ | |||
62 63 64 65 66 67 68 | log.Printf("No parser for %q found", name) panic("No default parser registered") } // ParseBlocks parses some input and returns a slice of block nodes. func ParseBlocks(inp *input.Input, m *meta.Meta, syntax string) ast.BlockSlice { bs := Get(syntax).ParseBlocks(inp, m, syntax) | | < | | | > < | > | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | log.Printf("No parser for %q found", name) panic("No default parser registered") } // ParseBlocks parses some input and returns a slice of block nodes. func ParseBlocks(inp *input.Input, m *meta.Meta, syntax string) ast.BlockSlice { bs := Get(syntax).ParseBlocks(inp, m, syntax) cleanupBlockSlice(bs) return bs } // ParseInlines parses some input and returns a slice of inline nodes. func ParseInlines(inp *input.Input, syntax string) ast.InlineSlice { return Get(syntax).ParseInlines(inp, syntax) } // ParseTitle parses the title of a zettel, always as Zettelmarkup func ParseTitle(title string) ast.InlineSlice { return ParseInlines(input.NewInput(title), meta.ValueSyntaxZmk) } // ParseZettel parses the zettel based on the syntax. func ParseZettel(zettel domain.Zettel, syntax string) *ast.ZettelNode { m := zettel.Meta inhMeta := runtime.AddDefaultValues(zettel.Meta) if syntax == "" { syntax, _ = inhMeta.Get(meta.KeySyntax) } title, _ := inhMeta.Get(meta.KeyTitle) parseMeta := inhMeta if syntax == meta.ValueSyntaxNone { parseMeta = m } return &ast.ZettelNode{ Zettel: zettel, Zid: m.Zid, InhMeta: inhMeta, Title: ParseTitle(title), Ast: ParseBlocks(input.NewInput(zettel.Content.AsString()), parseMeta, syntax), } } |
Changes to parser/zettelmark/block.go.
︙ | ︙ | |||
50 51 52 53 54 55 56 | success := false switch inp.Ch { case input.EOS: return nil, false case '\n', '\r': inp.EatEOL() | | > > > > > > > > > > > | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | success := false switch inp.Ch { case input.EOS: return nil, false case '\n', '\r': inp.EatEOL() for _, l := range cp.lists { if lits := len(l.Items); lits > 0 { l.Items[lits-1] = append(l.Items[lits-1], &nullItemNode{}) } } if cp.descrl != nil { defPos := len(cp.descrl.Descriptions) - 1 if ldds := len(cp.descrl.Descriptions[defPos].Descriptions); ldds > 0 { cp.descrl.Descriptions[defPos].Descriptions[ldds-1] = append( cp.descrl.Descriptions[defPos].Descriptions[ldds-1], &nullDescriptionNode{}) } } return nil, false case ':': bn, success = cp.parseColon() case '`', runeModGrave, '%': cp.clearStacked() bn, success = cp.parseVerbatim() case '"', '<': |
︙ | ︙ | |||
97 98 99 100 101 102 103 | if lastPara != nil { lastPara.Inlines = append(lastPara.Inlines, pn.Inlines...) return nil, true } return pn, false } | < < < < < < < < < < < < < < < | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | if lastPara != nil { lastPara.Inlines = append(lastPara.Inlines, pn.Inlines...) return nil, true } return pn, false } // parseColon determines which element should be parsed. func (cp *zmkP) parseColon() (ast.BlockNode, bool) { inp := cp.inp if inp.PeekN(1) == ':' { cp.clearStacked() return cp.parseRegion() } |
︙ | ︙ | |||
224 225 226 227 228 229 230 | var lastPara *ast.ParaNode inp.EatEOL() for { posL := inp.Pos switch inp.Ch { case fch: if cp.countDelim(fch) >= cnt { | > > > > > > > > > | > | > > > < < < < < < < < < < < < < < < < < > | > > | | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | var lastPara *ast.ParaNode inp.EatEOL() for { posL := inp.Pos switch inp.Ch { case fch: if cp.countDelim(fch) >= cnt { cp.clearStacked() // remove any lists defined in the region for inp.Ch == ' ' { inp.Next() } for { switch inp.Ch { case input.EOS, '\n', '\r': return rn, true } in := cp.parseInline() if in == nil { return rn, true } rn.Inlines = append(rn.Inlines, in) } } inp.SetPos(posL) case input.EOS: return nil, false } bn, cont := cp.parseBlock(lastPara) if bn != nil { rn.Blocks = append(rn.Blocks, bn) } if !cont { lastPara, _ = bn.(*ast.ParaNode) } } } // parseHeading parses a head line. func (cp *zmkP) parseHeading() (hn *ast.HeadingNode, success bool) { inp := cp.inp lvl := cp.countDelim(inp.Ch) if lvl < 3 { return nil, false } if lvl > 7 { lvl = 7 } if inp.Ch != ' ' { return nil, false } inp.Next() for inp.Ch == ' ' { inp.Next() } hn = &ast.HeadingNode{Level: lvl - 1} for { switch inp.Ch { case input.EOS, '\n', '\r': return hn, true } in := cp.parseInline() if in == nil { return hn, true } if inp.Ch == '{' { |
︙ | ︙ | |||
309 310 311 312 313 314 315 | var mapRuneNestedList = map[rune]ast.NestedListCode{ '*': ast.NestedListUnordered, '#': ast.NestedListOrdered, '>': ast.NestedListQuote, } | | | < < < < < < < | < < < < < < < < < < < | | > > > > > > > > > > > | | | < < | < < > | > | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | var mapRuneNestedList = map[rune]ast.NestedListCode{ '*': ast.NestedListUnordered, '#': ast.NestedListOrdered, '>': ast.NestedListQuote, } // parseList parses a list. func (cp *zmkP) parseNestedList() (res ast.BlockNode, success bool) { inp := cp.inp codes := []ast.NestedListCode{} loopInit: for { code, ok := mapRuneNestedList[inp.Ch] if !ok { panic(fmt.Sprintf("%q is not a region char", inp.Ch)) } codes = append(codes, code) inp.Next() switch inp.Ch { case '*', '#', '>': case ' ', input.EOS, '\n', '\r': break loopInit default: return nil, false } } for inp.Ch == ' ' { inp.Next() } if codes[len(codes)-1] != ast.NestedListQuote { switch inp.Ch { case input.EOS, '\n', '\r': return nil, false } } if len(codes) < len(cp.lists) { cp.lists = cp.lists[:len(codes)] } var ln *ast.NestedListNode newLnCount := 0 for i, code := range codes { if i < len(cp.lists) { if cp.lists[i].Code != code { ln = &ast.NestedListNode{Code: code} newLnCount++ cp.lists[i] = ln cp.lists = cp.lists[:i+1] } else { ln = cp.lists[i] } } else { ln = &ast.NestedListNode{Code: code} newLnCount++ cp.lists = append(cp.lists, ln) } } ln.Items = append(ln.Items, ast.ItemSlice{cp.parseLinePara()}) listDepth := len(cp.lists) for i := 0; i < newLnCount; i++ { childPos := listDepth - i - 1 parentPos := childPos - 1 if parentPos < 0 { return cp.lists[0], true } if prevItems := cp.lists[parentPos].Items; len(prevItems) > 0 { lastItem := len(prevItems) - 1 prevItems[lastItem] = append(prevItems[lastItem], cp.lists[childPos]) } else { cp.lists[parentPos].Items = []ast.ItemSlice{{cp.lists[childPos]}} } } return nil, true } // parseDefTerm parses a term of a definition list. func (cp *zmkP) parseDefTerm() (res ast.BlockNode, success bool) { inp := cp.inp inp.Next() if inp.Ch != ' ' { return nil, false } inp.Next() for inp.Ch == ' ' { inp.Next() } descrl := cp.descrl if descrl == nil { descrl = &ast.DescriptionListNode{} cp.descrl = descrl } descrl.Descriptions = append(descrl.Descriptions, ast.Description{}) defPos := len(descrl.Descriptions) - 1 |
︙ | ︙ | |||
431 432 433 434 435 436 437 | func (cp *zmkP) parseDefDescr() (res ast.BlockNode, success bool) { inp := cp.inp inp.Next() if inp.Ch != ' ' { return nil, false } inp.Next() | > | > | 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | func (cp *zmkP) parseDefDescr() (res ast.BlockNode, success bool) { inp := cp.inp inp.Next() if inp.Ch != ' ' { return nil, false } inp.Next() for inp.Ch == ' ' { inp.Next() } descrl := cp.descrl if descrl == nil || len(descrl.Descriptions) == 0 { return nil, false } defPos := len(descrl.Descriptions) - 1 if descrl.Descriptions[defPos].Term == nil { return nil, false |
︙ | ︙ | |||
574 575 576 577 578 579 580 | } // parseCell parses one single cell of a table row. func (cp *zmkP) parseCell() *ast.TableCell { inp := cp.inp var slice ast.InlineSlice for { | > | | < | | 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | } // parseCell parses one single cell of a table row. func (cp *zmkP) parseCell() *ast.TableCell { inp := cp.inp var slice ast.InlineSlice for { switch inp.Ch { case input.EOS, '\n', '\r': if len(slice) == 0 { return nil } fallthrough case '|': return &ast.TableCell{Inlines: slice} } slice = append(slice, cp.parseInline()) } } |
Changes to parser/zettelmark/inline.go.
︙ | ︙ | |||
121 122 123 124 125 126 127 | default: return cp.parseBackslashRest() } } func (cp *zmkP) parseBackslashRest() *ast.TextNode { inp := cp.inp | > | < | | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | default: return cp.parseBackslashRest() } } func (cp *zmkP) parseBackslashRest() *ast.TextNode { inp := cp.inp switch inp.Ch { case input.EOS, '\n', '\r': return &ast.TextNode{Text: "\\"} case ' ': inp.Next() return &ast.TextNode{Text: "\u00a0"} } pos := inp.Pos inp.Next() return &ast.TextNode{Text: inp.Src[pos:inp.Pos]} } |
︙ | ︙ | |||
175 176 177 178 179 180 181 | } return nil, false } func (cp *zmkP) parseReference(closeCh rune) (ref string, ins ast.InlineSlice, ok bool) { inp := cp.inp inp.Next() | > > > | < | > > > | > > > > > > > > > > > > | > > > | | < > > > > > | > > > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | } return nil, false } func (cp *zmkP) parseReference(closeCh rune) (ref string, ins ast.InlineSlice, ok bool) { inp := cp.inp inp.Next() for inp.Ch == ' ' { inp.Next() } hasSpace := false pos := inp.Pos loop: for { switch inp.Ch { case input.EOS: return "", nil, false case '\n', '\r', ' ': hasSpace = true case '|', closeCh: break loop } inp.Next() } if inp.Ch == '|' { // First part must be inline text if pos == inp.Pos { // [[| or {{| return "", nil, false } inp.SetPos(pos) loop1: for { switch inp.Ch { case input.EOS, '|': break loop1 } in := cp.parseInline() ins = append(ins, in) } inp.Next() pos = inp.Pos } else if hasSpace { return "", nil, false } inp.SetPos(pos) for inp.Ch == ' ' { inp.Next() pos = inp.Pos } loop2: for { switch inp.Ch { case input.EOS, '\n', '\r', ' ': return "", nil, false case closeCh: break loop2 } inp.Next() } ref = inp.Src[pos:inp.Pos] inp.Next() if inp.Ch != closeCh { return "", nil, false } inp.Next() return ref, ins, true } func (cp *zmkP) parseCite() (*ast.CiteNode, bool) { inp := cp.inp inp.Next() switch inp.Ch { case ' ', ',', '|', ']', '\n', '\r': return nil, false } |
︙ | ︙ | |||
290 291 292 293 294 295 296 | return nil, false } attrs := cp.parseAttributes(false) return &ast.FootnoteNode{Inlines: ins, Attrs: attrs}, true } func (cp *zmkP) parseLinkLikeRest() (ast.InlineSlice, bool) { | | > > > < | > > > | > | 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | return nil, false } attrs := cp.parseAttributes(false) return &ast.FootnoteNode{Inlines: ins, Attrs: attrs}, true } func (cp *zmkP) parseLinkLikeRest() (ast.InlineSlice, bool) { inp := cp.inp for inp.Ch == ' ' { inp.Next() } var ins ast.InlineSlice for inp.Ch != ']' { in := cp.parseInline() if in == nil { return nil, false } ins = append(ins, in) if _, ok := in.(*ast.BreakNode); ok { ch := cp.inp.Ch switch ch { case input.EOS, '\n', '\r': return nil, false } } } inp.Next() return ins, true } func (cp *zmkP) parseImage() (ast.InlineNode, bool) { |
︙ | ︙ | |||
356 357 358 359 360 361 362 | inp.Next() if inp.Ch != '%' { return nil, false } for inp.Ch == '%' { inp.Next() } | > | > > | | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | inp.Next() if inp.Ch != '%' { return nil, false } for inp.Ch == '%' { inp.Next() } for inp.Ch == ' ' { inp.Next() } pos := inp.Pos for { switch inp.Ch { case input.EOS, '\n', '\r': return &ast.LiteralNode{Code: ast.LiteralComment, Text: inp.Src[pos:inp.Pos]}, true } inp.Next() } } var mapRuneFormat = map[rune]ast.FormatCode{ |
︙ | ︙ | |||
391 392 393 394 395 396 397 | if !ok { panic(fmt.Sprintf("%q is not a formatting char", fch)) } inp.Next() // read 2nd formatting character if inp.Ch != fch { return nil, false } | < > | > > | > | 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | if !ok { panic(fmt.Sprintf("%q is not a formatting char", fch)) } inp.Next() // read 2nd formatting character if inp.Ch != fch { return nil, false } fn := &ast.FormatNode{Code: code} inp.Next() for { if inp.Ch == input.EOS { return nil, false } if inp.Ch == fch { inp.Next() if inp.Ch == fch { inp.Next() fn.Attrs = cp.parseAttributes(false) return fn, true } fn.Inlines = append(fn.Inlines, &ast.TextNode{Text: string(fch)}) } else if in := cp.parseInline(); in != nil { if _, ok := in.(*ast.BreakNode); ok { switch inp.Ch { case input.EOS, '\n', '\r': return nil, false } } fn.Inlines = append(fn.Inlines, in) } } } var mapRuneLiteral = map[rune]ast.LiteralCode{ |
︙ | ︙ |
Changes to parser/zettelmark/post-processor.go.
︙ | ︙ | |||
79 80 81 82 83 84 85 | } } } // VisitTable post-processes a table. func (pp *postProcessor) VisitTable(tn *ast.TableNode) { width := tableWidth(tn) | | | | > > > > > > > > > > > > > > < < < < < < < < < < < < < < < < < < < < < < < < < | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | } } } // VisitTable post-processes a table. func (pp *postProcessor) VisitTable(tn *ast.TableNode) { width := tableWidth(tn) tn.Align = make([]ast.Alignment, 0, width) for i := 0; i < width; i++ { tn.Align = append(tn.Align, ast.AlignDefault) } if len(tn.Rows) > 0 && isHeaderRow(tn.Rows[0]) { tn.Header = tn.Rows[0] tn.Rows = tn.Rows[1:] for pos, cell := range tn.Header { if inlines := cell.Inlines; len(inlines) > 0 { if textNode, ok := inlines[0].(*ast.TextNode); ok { textNode.Text = strings.TrimPrefix(textNode.Text, "=") } if textNode, ok := inlines[len(inlines)-1].(*ast.TextNode); ok { if tnl := len(textNode.Text); tnl > 0 { if align := getAlignment(textNode.Text[tnl-1]); align != ast.AlignDefault { tn.Align[pos] = align textNode.Text = textNode.Text[0 : tnl-1] } } } } } } if len(tn.Header) > 0 { tn.Header = appendCells(tn.Header, width, tn.Align) for i, cell := range tn.Header { pp.processCell(cell, tn.Align[i]) } } for i, row := range tn.Rows { tn.Rows[i] = appendCells(row, width, tn.Align) row = tn.Rows[i] for i, cell := range row { pp.processCell(cell, tn.Align[i]) } } } func tableWidth(tn *ast.TableNode) int { width := 0 for _, row := range tn.Rows { if width < len(row) { width = len(row) |
︙ | ︙ | |||
376 377 378 379 380 381 382 | // // Two text nodes are merged into one. // // Two spaces following a break are merged into a hard break. func (pp *postProcessor) processInlineSliceCopy(ins ast.InlineSlice) int { maxPos := len(ins) for { | > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | // // Two text nodes are merged into one. // // Two spaces following a break are merged into a hard break. func (pp *postProcessor) processInlineSliceCopy(ins ast.InlineSlice) int { maxPos := len(ins) for { again := false fromPos, toPos := 0, 0 for fromPos < maxPos { ins[toPos] = ins[fromPos] fromPos++ switch in := ins[toPos].(type) { case *ast.TextNode: for fromPos < maxPos { if tn, ok := ins[fromPos].(*ast.TextNode); ok { in.Text = in.Text + tn.Text fromPos++ } else { break } } case *ast.SpaceNode: if fromPos < maxPos { switch nn := ins[fromPos].(type) { case *ast.BreakNode: if len(in.Lexeme) > 1 { nn.Hard = true ins[toPos] = nn fromPos++ } case *ast.TextNode: if pp.inVerse { ins[toPos] = &ast.TextNode{Text: strings.Repeat("\u00a0", len(in.Lexeme)) + nn.Text} fromPos++ again = true } } } case *ast.BreakNode: if pp.inVerse { in.Hard = true } } toPos++ } for pos := toPos; pos < maxPos; pos++ { ins[pos] = nil // Allow excess nodes to be garbage collected. } if !again { return toPos } maxPos = toPos } } // processInlineSliceTail removes empty text nodes, breaks and spaces at the end. func (pp *postProcessor) processInlineSliceTail(ins ast.InlineSlice, toPos int) int { for toPos > 0 { switch n := ins[toPos-1].(type) { case *ast.TextNode: if len(n.Text) > 0 { return toPos |
︙ | ︙ |
Changes to parser/zettelmark/zettelmark.go.
︙ | ︙ | |||
74 75 76 77 78 79 80 | return false } key := string(inp.Src[posK:inp.Pos]) if inp.Ch != '=' { attrs[key] = "" return true } | | > > | > > > > > > | > > > > > > > > > > > > > > > > > > > > > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | return false } key := string(inp.Src[posK:inp.Pos]) if inp.Ch != '=' { attrs[key] = "" return true } if sameLine { switch inp.Ch { case input.EOS, '\n', '\r': return false } } return cp.parseAttributeValue(key, attrs, sameLine) } func (cp *zmkP) parseAttributeValue( key string, attrs map[string]string, sameLine bool) bool { inp := cp.inp inp.Next() if inp.Ch == '"' { inp.Next() var val string for { switch inp.Ch { case input.EOS: return false case '"': updateAttrs(attrs, key, val) inp.Next() return true case '\n', '\r': if sameLine { return false } inp.EatEOL() val += " " case '\\': inp.Next() switch inp.Ch { case input.EOS, '\n', '\r': return false } fallthrough default: val += string(inp.Ch) inp.Next() } } } posV := inp.Pos for { switch inp.Ch { case input.EOS: return false case '\n', '\r': if sameLine { return false } fallthrough case ' ', '}': updateAttrs(attrs, key, inp.Src[posV:inp.Pos]) return true } inp.Next() } } func updateAttrs(attrs map[string]string, key, val string) { if prevVal := attrs[key]; len(prevVal) > 0 { attrs[key] = prevVal + " " + val } else { attrs[key] = val |
︙ | ︙ | |||
164 165 166 167 168 169 170 | inp.Next() } if pos < inp.Pos { return &ast.Attributes{Attrs: map[string]string{"": inp.Src[pos:inp.Pos]}} } // No immediate name: skip spaces | | < < < < < < | < < | | | | | | < | | | > > | | | < < | | | | | | | | | | | < < | | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | inp.Next() } if pos < inp.Pos { return &ast.Attributes{Attrs: map[string]string{"": inp.Src[pos:inp.Pos]}} } // No immediate name: skip spaces cp.skipSpace(!sameLine) } pos := inp.Pos attrs, success := cp.doParseAttributes(sameLine) if sameLine || success { return attrs } inp.SetPos(pos) return nil } func (cp *zmkP) doParseAttributes(sameLine bool) (res *ast.Attributes, success bool) { inp := cp.inp if inp.Ch != '{' { return nil, false } inp.Next() attrs := map[string]string{} loop: for { cp.skipSpace(!sameLine) switch inp.Ch { case input.EOS: return nil, false case '}': break loop case '.': inp.Next() posC := inp.Pos for isNameRune(inp.Ch) { inp.Next() } if posC == inp.Pos { return nil, false } updateAttrs(attrs, "class", inp.Src[posC:inp.Pos]) case '=': delete(attrs, "") if !cp.parseAttributeValue("", attrs, sameLine) { return nil, false } default: if !cp.parseNormalAttribute(attrs, sameLine) { return nil, false } } switch inp.Ch { case '}': break loop case '\n', '\r': if sameLine { return nil, false } case ' ', ',': inp.Next() default: return nil, false } } inp.Next() return &ast.Attributes{Attrs: attrs}, true } func (cp *zmkP) skipSpace(eolIsSpace bool) { inp := cp.inp if eolIsSpace { for { switch inp.Ch { case ' ': inp.Next() case '\n', '\r': inp.EatEOL() default: return } } } for inp.Ch == ' ' { inp.Next() } } func isNameRune(ch rune) bool { return unicode.IsLetter(ch) || unicode.IsDigit(ch) || ch == '-' || ch == '_' } |
Changes to parser/zettelmark/zettelmark_test.go.
︙ | ︙ | |||
17 18 19 20 21 22 23 | "strings" "testing" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/input" "zettelstore.de/z/parser" | < < < < | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | "strings" "testing" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/input" "zettelstore.de/z/parser" ) type TestCase struct{ source, want string } type TestCases []TestCase func replace(s string, tcs TestCases) TestCases { var testCases TestCases |
︙ | ︙ |
Deleted place/change/change.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted place/constplace/base.css.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted place/constplace/base.mustache.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Added place/constplace/constdata.go.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package constplace stores zettel inside the executable. package constplace import ( "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" ) const ( syntaxTemplate = "mustache" ) var constZettelMap = map[id.Zid]constZettel{ id.ConfigurationZid: { constHeader{ meta.KeyTitle: "Zettelstore Runtime Configuration", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityOwner, meta.KeySyntax: meta.ValueSyntaxNone, }, "", }, id.BaseTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore Base HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<!DOCTYPE html> <html{{#Lang}} lang="{{Lang}}"{{/Lang}}> <head> <meta charset="utf-8"> <meta name="referrer" content="same-origin"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="generator" content="Zettelstore"> {{{MetaHeader}}} <link rel="stylesheet" href="{{{StylesheetURL}}}"> <title>{{Title}}</title> </head> <body> <nav class="zs-menu"> <a href="{{{HomeURL}}}">Home</a> {{#WithUser}} <div class="zs-dropdown"> <button>User</button> <nav class="zs-dropdown-content"> {{#WithAuth}} {{#UserIsValid}} <a href="{{{UserZettelURL}}}">{{UserIdent}}</a> {{/UserIsValid}} {{^UserIsValid}} <a href="{{{LoginURL}}}">Login</a> {{/UserIsValid}} {{#UserIsValid}} <a href="{{{UserLogoutURL}}}">Logout</a> {{/UserIsValid}} {{/WithAuth}} </nav> </div> {{/WithUser}} <div class="zs-dropdown"> <button>Lists</button> <nav class="zs-dropdown-content"> <a href="{{{ListZettelURL}}}">List Zettel</a> <a href="{{{ListRolesURL}}}">List Roles</a> <a href="{{{ListTagsURL}}}">List Tags</a> </nav> </div> {{#CanCreate}} <div class="zs-dropdown"> <button>New</button> <nav class="zs-dropdown-content"> {{#NewZettelLinks}} <a href="{{{URL}}}">{{Text}}</a> {{/NewZettelLinks}} </nav> </div> {{/CanCreate}} <form action="{{{SearchURL}}}"> <input type="text" placeholder="Search.." name="s"> </form> </nav> <main class="content"> {{{Content}}} </main> {{#FooterHTML}} <footer> {{{FooterHTML}}} </footer> {{/FooterHTML}} </body> </html>`}, id.LoginTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore Login Form HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<article> <header> <h1>{{Title}}</h1> </header> {{#Retry}} <div class="zs-indication zs-error">Wrong user name / password. Try again.</div> {{/Retry}} <form method="POST" action="?_format=html"> <div> <label for="username">User name</label> <input class="zs-input" type="text" id="username" name="username" placeholder="Your user name.." autofocus> </div> <div> <label for="password">Password</label> <input class="zs-input" type="password" id="password" name="password" placeholder="Your password.."> </div> <input class="zs-button" type="submit" value="Login"> </form> </article>`}, id.ListTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore List Meta HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<nav> <header> <h1>{{Title}}</h1> </header> <ul> {{#Metas}}<li><a href="{{{URL}}}">{{{Text}}}</a></li> {{/Metas}}</ul> {{#HasPrevNext}} <p> {{#HasPrev}} <a href="{{{PrevURL}}}" rel="prev">Prev</a> {{#HasNext}},{{/HasNext}} {{/HasPrev}} {{#HasNext}} <a href="{{{NextURL}}}" rel="next">Next</a> {{/HasNext}} </p> {{/HasPrevNext}} </nav>`}, id.DetailTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore Detail HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<article> <header> <h1>{{{HTMLTitle}}}</h1> <div class="zs-meta"> {{#CanWrite}}<a href="{{{EditURL}}}">Edit</a> ·{{/CanWrite}} {{Zid}} · <a href="{{{InfoURL}}}">Info</a> · (<a href="{{{RoleURL}}}">{{RoleText}}</a>) {{#HasTags}}· {{#Tags}} <a href="{{{URL}}}">{{Text}}</a>{{/Tags}}{{/HasTags}} {{#CanCopy}}· <a href="{{{CopyURL}}}">Copy</a>{{/CanCopy}} {{#CanFolge}}· <a href="{{{FolgeURL}}}">Folge</a>{{/CanFolge}} {{#FolgeRefs}}<br>Folge: {{{FolgeRefs}}}{{/FolgeRefs}} {{#PrecursorRefs}}<br>Precursor: {{{PrecursorRefs}}}{{/PrecursorRefs}} {{#HasExtURL}}<br>URL: <a href="{{{ExtURL}}}"{{{ExtNewWindow}}}>{{ExtURL}}</a>{{/HasExtURL}} </div> </header> {{{Content}}} {{#HasBackLinks}} <details> <summary>Links to this zettel</summary> <ul> {{#BackLinks}} <li><a href="{{{URL}}}">{{Text}}</a></li> {{/BackLinks}} </ul> </details> {{/HasBackLinks}} </article>`}, id.InfoTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore Info HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<article> <header> <h1>Information for Zettel {{Zid}}</h1> <a href="{{{WebURL}}}">Web</a> · <a href="{{{ContextURL}}}">Context</a> {{#CanWrite}} · <a href="{{{EditURL}}}">Edit</a>{{/CanWrite}} {{#CanFolge}} · <a href="{{{FolgeURL}}}">Folge</a>{{/CanFolge}} {{#CanCopy}} · <a href="{{{CopyURL}}}">Copy</a>{{/CanCopy}} {{#CanRename}}· <a href="{{{RenameURL}}}">Rename</a>{{/CanRename}} {{#CanDelete}}· <a href="{{{DeleteURL}}}">Delete</a>{{/CanDelete}} </header> <h2>Interpreted Metadata</h2> <table>{{#MetaData}}<tr><td>{{Key}}</td><td>{{{Value}}}</td></tr>{{/MetaData}}</table> {{#HasLinks}} <h2>References</h2> {{#HasLocLinks}} <h3>Local</h3> <ul> {{#LocLinks}} <li><a href="{{{.}}}">{{.}}</a></li> {{/LocLinks}} </ul> {{/HasLocLinks}} {{#HasExtLinks}} <h3>External</h3> <ul> {{#ExtLinks}} <li><a href="{{{.}}}"{{{ExtNewWindow}}}>{{.}}</a></li> {{/ExtLinks}} </ul> {{/HasExtLinks}} {{/HasLinks}} <h2>Parts and format</h3> <table> {{#Matrix}} <tr> {{#Elements}}{{#HasURL}}<td><a href="{{{URL}}}">{{Text}}</td>{{/HasURL}}{{^HasURL}}<th>{{Text}}</th>{{/HasURL}} {{/Elements}} </tr> {{/Matrix}} </table> </article>`}, id.ContextTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore Context HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<nav> <header> <h1>{{Title}}</h1> <div class="zs-meta"> <a href="{{{InfoURL}}}">Info</a> · <a href="?dir=backward">Backward</a> · <a href="?dir=both">Both</a> · <a href="?dir=forward">Forward</a> · Depth:{{#Depths}} <a href="{{{URL}}}">{{{Text}}}</a>{{/Depths}} </div> </header> <p><a href="{{{Start.URL}}}">{{{Start.Text}}}</a></p> <ul> {{#Metas}}<li><a href="{{{URL}}}">{{{Text}}}</a></li> {{/Metas}}</ul> </nav>`}, id.FormTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore Form HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<article> <header> <h1>{{Heading}}</h1> </header> <form method="POST"> <div> <label for="title">Title</label> <input class="zs-input" type="text" id="title" name="title" placeholder="Title.." value="{{MetaTitle}}" autofocus> </div> <div> <div> <label for="role">Role</label> <input class="zs-input" type="text" id="role" name="role" placeholder="role.." value="{{MetaRole}}"> </div> <label for="tags">Tags</label> <input class="zs-input" type="text" id="tags" name="tags" placeholder="#tag" value="{{MetaTags}}"> </div> <div> <label for="meta">Metadata</label> <textarea class="zs-input" id="meta" name="meta" rows="4" placeholder="metakey: metavalue"> {{#MetaPairsRest}} {{Key}}: {{Value}} {{/MetaPairsRest}} </textarea> </div> <div> <label for="syntax">Syntax</label> <input class="zs-input" type="text" id="syntax" name="syntax" placeholder="syntax.." value="{{MetaSyntax}}"> </div> <div> {{#IsTextContent}} <label for="content">Content</label> <textarea class="zs-input zs-content" id="meta" name="content" rows="20" placeholder="Your content..">{{Content}}</textarea> {{/IsTextContent}} </div> <input class="zs-button" type="submit" value="Submit"> </form> </article>`, }, id.RenameTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore Rename Form HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<article> <header> <h1>Rename Zettel {{.Zid}}</h1> </header> <p>Do you really want to rename this zettel?</p> <form method="POST"> <div> <label for="newid">New zettel id</label> <input class="zs-input" type="text" id="newzid" name="newzid" placeholder="ZID.." value="{{Zid}}" autofocus> </div> <input type="hidden" id="curzid" name="curzid" value="{{Zid}}"> <input class="zs-button" type="submit" value="Rename"> </form> <dl> {{#MetaPairs}} <dt>{{Key}}:</dt><dd>{{Value}}</dd> {{/MetaPairs}} </dl> </article>`, }, id.DeleteTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore Delete HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<article> <header> <h1>Delete Zettel {{Zid}}</h1> </header> <p>Do you really want to delete this zettel?</p> <dl> {{#MetaPairs}} <dt>{{Key}}:</dt><dd>{{Value}}</dd> {{/MetaPairs}} </dl> <form method="POST"> <input class="zs-button" type="submit" value="Delete"> </form> </article> {{end}}`, }, id.RolesTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore List Roles HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<nav> <header> <h1>Currently used roles</h1> </header> <ul> {{#Roles}}<li><a href="{{{URL}}}">{{Text}}</a></li> {{/Roles}}</ul> </nav>`}, id.TagsTemplateZid: { constHeader{ meta.KeyTitle: "Zettelstore List Tags HTML Template", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityExpert, meta.KeySyntax: syntaxTemplate, }, `<nav> <header> <h1>Currently used tags</h1> <div class="zs-meta"> <a href="{{{#ListTagsURL}}}">All</a>{{#MinCounts}}, <a href="{{{URL}}}">{{Count}}</a>{{/MinCounts}} </div> </header> {{#Tags}} <a href="{{{URL}}}" style="font-size:{{Size}}%">{{Name}}</a><sup>{{Count}}</sup> {{/Tags}} </nav>`}, id.BaseCSSZid: { constHeader{ meta.KeyTitle: "Zettelstore Base CSS", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeyVisibility: meta.ValueVisibilityPublic, meta.KeySyntax: "css", }, `/* Default CSS */ *,*::before,*::after { box-sizing: border-box; } html { font-size: 1rem; font-family: serif; scroll-behavior: smooth; height: 100%; } body { margin: 0; min-height: 100vh; text-rendering: optimizeSpeed; line-height: 1.4; overflow-x: hidden; background-color: #f8f8f8 ; height: 100%; } nav.zs-menu { background-color: hsl(210, 28%, 90%); overflow: auto; white-space: nowrap; font-family: sans-serif; padding-left: .5rem; } nav.zs-menu > a { float:left; display: inline-block; text-align: center; padding:.41rem .5rem; text-decoration: none; color:black; } nav.zs-menu > a:hover, .zs-dropdown:hover button { background-color: hsl(210, 28%, 80%); } nav.zs-menu form { float: right; } nav.zs-menu form input[type=text] { padding: .12rem; border: none; margin-top: .25rem; margin-right: .5rem; } .zs-dropdown { float: left; overflow: hidden; } .zs-dropdown > button { font-size: 16px; border: none; outline: none; color: black; padding:.41rem .5rem; background-color: inherit; font-family: inherit; margin: 0; } .zs-dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .zs-dropdown-content > a { float: none; color: black; padding:.41rem .5rem; text-decoration: none; display: block; text-align: left; } .zs-dropdown-content > a:hover { background-color: hsl(210, 28%, 75%); } .zs-dropdown:hover > .zs-dropdown-content { display: block; } main { padding: 0 1rem; } article > * + * { margin-top: .5rem; } article header { padding: 0; margin: 0; } h1,h2,h3,h4,h5,h6 { font-family:sans-serif; font-weight:normal } h1 { font-size:1.5rem; margin:.65rem 0 } h2 { font-size:1.25rem; margin:.70rem 0 } h3 { font-size:1.15rem; margin:.75rem 0 } h4 { font-size:1.05rem; margin;.8rem 0; font-weight: bold } h5 { font-size:1.05rem; margin;.8rem 0 } h6 { font-size:1.05rem; margin;.8rem 0; font-weight: lighter } p { margin: .5rem 0 0 0; } ol,ul { padding-left: 1.1rem; } li,figure,figcaption,dl { margin: 0; } dt { margin: .5rem 0 0 0; } dt+dd { margin-top: 0; } dd { margin: .5rem 0 0 2rem; } dd > p:first-child { margin: 0 0 0 0; } blockquote { border-left: 0.5rem solid lightgray; padding-left: 1rem; margin-left: 1rem; margin-right: 2rem; font-style: italic; } blockquote p { margin-bottom: .5rem; } blockquote cite { font-style: normal; } table { border-collapse: collapse; border-spacing: 0; max-width: 100%; } th,td { text-align: left; padding: .25rem .5rem; } td { border-bottom: 1px solid hsl(0, 0%, 85%); } thead th { border-bottom: 2px solid hsl(0, 0%, 70%); } tfoot th { border-top: 2px solid hsl(0, 0%, 70%); } main form { padding: 0 .5em; margin: .5em 0 0 0; } main form:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; } main form div { margin: .5em 0 0 0 } input { font-family: monospace; } input[type="submit"],button,select { font: inherit; } label { font-family: sans-serif; font-size:.9rem } label::after { content:":" } textarea { font-family: monospace; resize: vertical; width: 100%; } .zs-input { padding: .5em; display:block; border:none; border-bottom:1px solid #ccc; width:100%; } .zs-button { float:right; margin: .5em 0 .5em 1em; } a:not([class]) { text-decoration-skip-ink: auto; } .zs-broken { text-decoration: line-through; } img { max-width: 100%; } .zs-endnotes { padding-top: .5rem; border-top: 1px solid; } code,pre,kbd { font-family: monospace; font-size: 85%; } code { padding: .1rem .2rem; background: #f0f0f0; border: 1px solid #ccc; border-radius: .25rem; } pre { padding: .5rem .7rem; max-width: 100%; overflow: auto; border: 1px solid #ccc; border-radius: .5rem; background: #f0f0f0; } pre code { font-size: 95%; position: relative; padding: 0; border: none; } div.zs-indication { padding: .5rem .7rem; max-width: 100%; border-radius: .5rem; border: 1px solid black; } div.zs-indication p:first-child { margin-top: 0; } span.zs-indication { border: 1px solid black; border-radius: .25rem; padding: .1rem .2rem; font-size: 95%; } .zs-example { border-style: dotted !important } .zs-error { background-color: lightpink; border-style: none !important; font-weight: bold; } kbd { background: hsl(210, 5%, 100%); border: 1px solid hsl(210, 5%, 70%); border-radius: .25rem; padding: .1rem .2rem; font-size: 75%; } .zs-meta { font-size:.75rem; color:#444; margin-bottom:1rem; } .zs-meta a { color:#444; } h1+.zs-meta { margin-top:-1rem; } details > summary { width: 100%; background-color: #eee; font-family:sans-serif; } details > ul { margin-top:0; padding-left:2rem; background-color: #eee; } footer { padding: 0 1rem; } @media (prefers-reduced-motion: reduce) { * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; } }`}, id.TOCNewTemplateZid: { constHeader{ meta.KeyTitle: "New Menu", meta.KeyRole: meta.ValueRoleConfiguration, meta.KeySyntax: meta.ValueSyntaxZmk, }, `This zettel lists all zettel that should act as a template for new zettel. These zettel will be included in the ""New"" menu of the WebUI. * [[New Zettel|00000000090001]] * [[New User|00000000090002]]`}, id.TemplateNewZettelZid: { constHeader{ meta.KeyTitle: "New Zettel", meta.KeyRole: meta.ValueRoleZettel, meta.KeySyntax: meta.ValueSyntaxZmk, }, ""}, id.TemplateNewUserZid: { constHeader{ meta.KeyTitle: "New User", meta.KeyRole: meta.ValueRoleUser, meta.KeyCredential: "", meta.KeyUserID: "", meta.KeyUserRole: meta.ValueUserRoleReader, meta.KeySyntax: meta.ValueSyntaxNone, }, ""}, id.DefaultHomeZid: { constHeader{ meta.KeyTitle: "Home", meta.KeyRole: meta.ValueRoleZettel, meta.KeySyntax: meta.ValueSyntaxZmk, }, `=== Thank you for using Zettelstore! You will find the lastest information about Zettelstore at [[https://zettelstore.de]]. Check that website regulary for [[upgrades|https://zettelstore.de/home/doc/trunk/www/download.wiki]] to the latest version. You should consult the [[change log|https://zettelstore.de/home/doc/trunk/www/changes.wiki]] before upgrading. Sometimes, you have to edit some of your Zettelstore-related zettel before upgrading. Since Zettelstore is currently in a development state, every upgrade might fix some of your problems. To check for versions, there is a zettel with the [[current version|00000000000001]] of your Zettelstore. If you have problems concerning Zettelstore, do not hesitate to get in [[contact with the main developer|mailto:ds@zettelstore.de]]. === Reporting errors If you have encountered an error, please include the content of the following zettel in your mail: * [[Zettelstore Version|00000000000001]] * [[Zettelstore Operating System|00000000000003]] * [[Zettelstore Startup Configuration|00000000000096]] * [[Zettelstore Startup Values|00000000000098]] * [[Zettelstore Runtime Configuration|00000000000100]] Additionally, you have to describe, what you have done before that error occurs and what you have expected instead. Please do not forget to include the error message, if there is one. Some of above Zettelstore zettel can only be retrieved if you enabled ""expert mode"". Otherwise, only some zettel are linked. To enable expert mode, edit the zettel [[Zettelstore Runtime Configuration|00000000000100]]: please set the metadata value of the key ''expert-mode'' to true. To do you, enter the string ''expert-mode:true'' inside the edit view of the metadata. === Information about this zettel This zettel is your home zettel. It is part of the Zettelstore software itself. Every time you click on the [[Home|//]] link in the menu bar, you will be redirected to this zettel. You can change the content of this zettel by clicking on ""Edit"" above. This allows you to customize your home zettel. Alternatively, you can designate another zettel as your home zettel. Edit the [[Zettelstore Runtime Configuration|00000000000100]] by adding the metadata key ''home-zettel''. Its value is the identifier of the zettel that should act as the new home zettel. You will find the identifier of each zettel between their ""Edit"" and the ""Info"" link above. The identifier of this zettel is ''00010000000000''. If you provide a wrong identifier, this zettel will be shown as the home zettel. Take a look inside the manual for further details. `}, } |
Changes to place/constplace/constplace.go.
︙ | ︙ | |||
9 10 11 12 13 14 15 | //----------------------------------------------------------------------------- // Package constplace places zettel inside the executable. package constplace import ( "context" | < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | //----------------------------------------------------------------------------- // Package constplace places zettel inside the executable. package constplace import ( "context" "net/url" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" "zettelstore.de/z/place" "zettelstore.de/z/place/manager" ) func init() { manager.Register( " const", func(u *url.URL, cdata *manager.ConnectData) (place.Place, error) { return &constPlace{zettel: constZettelMap, filter: cdata.Filter}, nil }) } type constHeader map[string]string func makeMeta(zid id.Zid, h constHeader) *meta.Meta { |
︙ | ︙ | |||
55 56 57 58 59 60 61 | func (cp *constPlace) Location() string { return "const:" } func (cp *constPlace) CanCreateZettel(ctx context.Context) bool { return false } | | > | > | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | func (cp *constPlace) Location() string { return "const:" } func (cp *constPlace) CanCreateZettel(ctx context.Context) bool { return false } func (cp *constPlace) CreateZettel( ctx context.Context, zettel domain.Zettel) (id.Zid, error) { return id.Invalid, place.ErrReadOnly } func (cp *constPlace) GetZettel( ctx context.Context, zid id.Zid) (domain.Zettel, error) { if z, ok := cp.zettel[zid]; ok { return domain.Zettel{Meta: makeMeta(zid, z.header), Content: z.content}, nil } return domain.Zettel{}, place.ErrNotFound } func (cp *constPlace) GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) { |
︙ | ︙ | |||
81 82 83 84 85 86 87 | result := id.NewSetCap(len(cp.zettel)) for zid := range cp.zettel { result[zid] = true } return result, nil } | | > > | | | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | result := id.NewSetCap(len(cp.zettel)) for zid := range cp.zettel { result[zid] = true } return result, nil } func (cp *constPlace) SelectMeta( ctx context.Context, f *place.Filter, s *place.Sorter) (res []*meta.Meta, err error) { hasMatch := place.CreateFilterFunc(f) for zid, zettel := range cp.zettel { m := makeMeta(zid, zettel.header) cp.filter.Enrich(ctx, m) if hasMatch(m) { res = append(res, m) } } return place.ApplySorter(res, s), nil } func (cp *constPlace) CanUpdateZettel(ctx context.Context, zettel domain.Zettel) bool { return false } func (cp *constPlace) UpdateZettel(ctx context.Context, zettel domain.Zettel) error { |
︙ | ︙ | |||
124 125 126 127 128 129 130 | return place.ErrNotFound } func (cp *constPlace) ReadStats(st *place.Stats) { st.ReadOnly = true st.Zettel = len(cp.zettel) } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 126 127 128 129 130 131 132 | return place.ErrNotFound } func (cp *constPlace) ReadStats(st *place.Stats) { st.ReadOnly = true st.Zettel = len(cp.zettel) } |
Deleted place/constplace/context.mustache.
|
| < < < < < < < < < < < < < < < < |
Deleted place/constplace/delete.mustache.
|
| < < < < < < < < < < < < < < < |
Deleted place/constplace/error.mustache.
|
| < < < < < < |
Deleted place/constplace/form.mustache.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted place/constplace/home.zettel.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted place/constplace/info.mustache.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted place/constplace/listroles.mustache.
|
| < < < < < < < < |
Deleted place/constplace/listtags.mustache.
|
| < < < < < < < < < < |
Deleted place/constplace/listzettel.mustache.
|
| < < < < < < < < < < < < < < < < < < < |
Deleted place/constplace/login.mustache.
|
| < < < < < < < < < < < < < < < < < < < |
Deleted place/constplace/newtoc.zettel.
|
| < < < < |
Deleted place/constplace/rename.mustache.
|
| < < < < < < < < < < < < < < < < < < < |
Deleted place/constplace/zettel.mustache.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Changes to place/dirplace/directory/directory.go.
︙ | ︙ | |||
11 12 13 14 15 16 17 | // Package directory manages the directory part of a dirstore. package directory import ( "time" "zettelstore.de/z/domain/id" | | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | // Package directory manages the directory part of a dirstore. package directory import ( "time" "zettelstore.de/z/domain/id" "zettelstore.de/z/place" ) // Service specifies a directory scan service. type Service struct { dirPath string rescanTime time.Duration done chan struct{} cmds chan dirCmd infos chan<- place.ChangeInfo } // NewService creates a new directory service. func NewService(directoryPath string, rescanTime time.Duration, chci chan<- place.ChangeInfo) *Service { srv := &Service{ dirPath: directoryPath, rescanTime: rescanTime, cmds: make(chan dirCmd), infos: chci, } return srv |
︙ | ︙ | |||
59 60 61 62 63 64 65 | // Stop stops the directory service. func (srv *Service) Stop() { close(srv.done) srv.done = nil } | | | | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | // Stop stops the directory service. func (srv *Service) Stop() { close(srv.done) srv.done = nil } func (srv *Service) notifyChange(reason place.ChangeReason, zid id.Zid) { if chci := srv.infos; chci != nil { chci <- place.ChangeInfo{Reason: reason, Zid: zid} } } // NumEntries returns the number of managed zettel. func (srv *Service) NumEntries() int { resChan := make(chan resNumEntries) srv.cmds <- &cmdNumEntries{resChan} |
︙ | ︙ |
Changes to place/dirplace/directory/entry.go.
1 | //----------------------------------------------------------------------------- | | > > > | > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package directory manages the directory part of a dirstore. package directory import ( "strings" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" ) // MetaSpec defines all possibilities where meta data can be stored. type MetaSpec int // Constants for MetaSpec const ( MetaSpecUnknown MetaSpec = iota |
︙ | ︙ | |||
34 35 36 37 38 39 40 | Duplicates bool // multiple content files } // IsValid checks whether the entry is valid. func (e *Entry) IsValid() bool { return e.Zid.IsValid() } | > > > > > > > > > > > > > > > > > > > > | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | Duplicates bool // multiple content files } // IsValid checks whether the entry is valid. func (e *Entry) IsValid() bool { return e.Zid.IsValid() } var alternativeSyntax = map[string]string{ "htm": "html", } func (e *Entry) calculateSyntax() string { ext := strings.ToLower(e.ContentExt) if syntax, ok := alternativeSyntax[ext]; ok { return syntax } return ext } // CalcDefaultMeta returns metadata with default values for the given entry. func (e *Entry) CalcDefaultMeta() *meta.Meta { m := meta.New(e.Zid) m.Set(meta.KeyTitle, e.Zid.String()) m.Set(meta.KeySyntax, e.calculateSyntax()) return m } |
Changes to place/dirplace/directory/service.go.
︙ | ︙ | |||
13 14 15 16 17 18 19 | import ( "log" "time" "zettelstore.de/z/domain/id" "zettelstore.de/z/place" | < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import ( "log" "time" "zettelstore.de/z/domain/id" "zettelstore.de/z/place" ) // ping sends every tick a signal to reload the directory list func ping(tick chan<- struct{}, rescanTime time.Duration, done <-chan struct{}) { ticker := time.NewTicker(rescanTime) defer close(tick) for { |
︙ | ︙ | |||
108 109 110 111 112 113 114 | curMap = newMap newMap = nil if ready != nil { ready <- len(curMap) close(ready) ready = nil } | | | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | curMap = newMap newMap = nil if ready != nil { ready <- len(curMap) close(ready) ready = nil } srv.notifyChange(place.OnReload, id.Invalid) case fileStatusError: log.Println("DIRPLACE", "ERROR", ev.err) case fileStatusUpdate: srv.processFileUpdateEvent(ev, curMap, newMap) case fileStatusDelete: srv.processFileDeleteEvent(ev, curMap, newMap) } case cmd, ok := <-srv.cmds: if ok { cmd.run(curMap) } } } } func (srv *Service) processFileUpdateEvent(ev *fileEvent, curMap, newMap dirMap) { if newMap != nil { dirMapUpdate(newMap, ev) } else { dirMapUpdate(curMap, ev) srv.notifyChange(place.OnUpdate, ev.zid) } } func (srv *Service) processFileDeleteEvent(ev *fileEvent, curMap, newMap dirMap) { if newMap != nil { deleteFromMap(newMap, ev) } else { deleteFromMap(curMap, ev) srv.notifyChange(place.OnDelete, ev.zid) } } type dirCmd interface { run(m dirMap) } |
︙ | ︙ |
Changes to place/dirplace/directory/watch.go.
︙ | ︙ | |||
8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // under this license. //----------------------------------------------------------------------------- // Package directory manages the directory part of a directory place. package directory import ( "os" "path/filepath" "regexp" "time" "github.com/fsnotify/fsnotify" | > | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // under this license. //----------------------------------------------------------------------------- // Package directory manages the directory part of a directory place. package directory import ( "io/ioutil" "os" "path/filepath" "regexp" "time" "github.com/fsnotify/fsnotify" |
︙ | ︙ | |||
94 95 96 97 98 99 100 | } return sendEvent(event) } reloadStartEvent := &fileEvent{status: fileStatusReloadStart} reloadEndEvent := &fileEvent{status: fileStatusReloadEnd} reloadFiles := func() bool { | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | } return sendEvent(event) } reloadStartEvent := &fileEvent{status: fileStatusReloadStart} reloadEndEvent := &fileEvent{status: fileStatusReloadEnd} reloadFiles := func() bool { files, err := ioutil.ReadDir(directory) if err != nil { if res := sendError(err); res != sendDone { return res == sendReload } return true } |
︙ | ︙ | |||
116 117 118 119 120 121 122 | watcher, err = fsnotify.NewWatcher() if err != nil { if res := sendError(err); res != sendDone { return res == sendReload } } | | < < < | | | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | watcher, err = fsnotify.NewWatcher() if err != nil { if res := sendError(err); res != sendDone { return res == sendReload } } for _, file := range files { if !file.Mode().IsRegular() { continue } name := file.Name() match := matchValidFileName(name) if len(match) > 0 { path := filepath.Join(directory, name) if res := sendFileEvent(fileStatusUpdate, path, match); res != sendDone { return res == sendReload } } |
︙ | ︙ |
Changes to place/dirplace/dirplace.go.
︙ | ︙ | |||
23 24 25 26 27 28 29 | "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" "zettelstore.de/z/place/dirplace/directory" | < < | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" "zettelstore.de/z/place/dirplace/directory" "zettelstore.de/z/place/manager" ) func init() { manager.Register("dir", func(u *url.URL, cdata *manager.ConnectData) (place.Place, error) { path := getDirPath(u) if _, err := os.Stat(path); os.IsNotExist(err) { return nil, err } dp := dirPlace{ u: u, readonly: getQueryBool(u, "readonly"), |
︙ | ︙ | |||
134 135 136 137 138 139 140 | return nil } func (dp *dirPlace) CanCreateZettel(ctx context.Context) bool { return !dp.readonly } | > | | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | return nil } func (dp *dirPlace) CanCreateZettel(ctx context.Context) bool { return !dp.readonly } func (dp *dirPlace) CreateZettel( ctx context.Context, zettel domain.Zettel) (id.Zid, error) { if dp.readonly { return id.Invalid, place.ErrReadOnly } meta := zettel.Meta entry := dp.dirSrv.GetNew() meta.Zid = entry.Zid |
︙ | ︙ | |||
187 188 189 190 191 192 193 | result := id.NewSetCap(len(entries)) for _, entry := range entries { result[entry.Zid] = true } return result, nil } | | > > > < > | | | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | result := id.NewSetCap(len(entries)) for _, entry := range entries { result[entry.Zid] = true } return result, nil } func (dp *dirPlace) SelectMeta( ctx context.Context, f *place.Filter, s *place.Sorter) (res []*meta.Meta, err error) { hasMatch := place.CreateFilterFunc(f) entries := dp.dirSrv.GetEntries() res = make([]*meta.Meta, 0, len(entries)) for _, entry := range entries { // TODO: execute requests in parallel m, err1 := getMeta(dp, &entry, entry.Zid) err = err1 if err != nil { continue } dp.cleanupMeta(ctx, m) dp.cdata.Filter.Enrich(ctx, m) if hasMatch(m) { res = append(res, m) } } if err != nil { return nil, err } return place.ApplySorter(res, s), nil } func (dp *dirPlace) CanUpdateZettel(ctx context.Context, zettel domain.Zettel) bool { return !dp.readonly } func (dp *dirPlace) UpdateZettel(ctx context.Context, zettel domain.Zettel) error { |
︙ | ︙ | |||
229 230 231 232 233 234 235 | } entry := dp.dirSrv.GetEntry(meta.Zid) if !entry.IsValid() { // Existing zettel, but new in this place. entry.Zid = meta.Zid dp.updateEntryFromMeta(&entry, meta) } else if entry.MetaSpec == directory.MetaSpecNone { | < | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | } entry := dp.dirSrv.GetEntry(meta.Zid) if !entry.IsValid() { // Existing zettel, but new in this place. entry.Zid = meta.Zid dp.updateEntryFromMeta(&entry, meta) } else if entry.MetaSpec == directory.MetaSpecNone { if defaultMeta := entry.CalcDefaultMeta(); !meta.Equal(defaultMeta, true) { dp.updateEntryFromMeta(&entry, meta) dp.dirSrv.UpdateEntry(&entry) } } return setZettel(dp, &entry, zettel) } |
︙ | ︙ |
Changes to place/dirplace/service.go.
︙ | ︙ | |||
8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // under this license. //----------------------------------------------------------------------------- // Package dirplace provides a directory-based zettel place. package dirplace import ( "os" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/input" "zettelstore.de/z/place/dirplace/directory" | > < | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | // under this license. //----------------------------------------------------------------------------- // Package dirplace provides a directory-based zettel place. package dirplace import ( "io/ioutil" "os" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/input" "zettelstore.de/z/place/dirplace/directory" ) func fileService(num uint32, cmds <-chan fileCmd) { for cmd := range cmds { cmd.run() } } |
︙ | ︙ | |||
50 51 52 53 54 55 56 | } type resGetMeta struct { meta *meta.Meta err error } func (cmd *fileGetMeta) run() { | < | | | | | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | } type resGetMeta struct { meta *meta.Meta err error } func (cmd *fileGetMeta) run() { var m *meta.Meta var err error switch cmd.entry.MetaSpec { case directory.MetaSpecFile: m, err = parseMetaFile(cmd.entry.Zid, cmd.entry.MetaPath) case directory.MetaSpecHeader: m, _, err = parseMetaContentFile(cmd.entry.Zid, cmd.entry.ContentPath) default: m = cmd.entry.CalcDefaultMeta() } if err == nil { cleanupMeta(m, cmd.entry) } cmd.rc <- resGetMeta{m, err} } // COMMAND: getMetaContent ---------------------------------------- // // Retrieves the meta data and the content of a zettel. |
︙ | ︙ | |||
94 95 96 97 98 99 100 | } func (cmd *fileGetMetaContent) run() { var m *meta.Meta var content string var err error | < | | | | | | | | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | } func (cmd *fileGetMetaContent) run() { var m *meta.Meta var content string var err error switch cmd.entry.MetaSpec { case directory.MetaSpecFile: m, err = parseMetaFile(cmd.entry.Zid, cmd.entry.MetaPath) if err == nil { content, err = readFileContent(cmd.entry.ContentPath) } case directory.MetaSpecHeader: m, content, err = parseMetaContentFile(cmd.entry.Zid, cmd.entry.ContentPath) default: m = cmd.entry.CalcDefaultMeta() content, err = readFileContent(cmd.entry.ContentPath) } if err == nil { cleanupMeta(m, cmd.entry) } cmd.rc <- resGetMetaContent{m, content, err} } // COMMAND: setZettel ---------------------------------------- // // Writes a new or exsting zettel. |
︙ | ︙ | |||
224 225 226 227 228 229 230 | } cmd.rc <- err } // Utility functions ---------------------------------------- func readFileContent(path string) (string, error) { | | | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | } cmd.rc <- err } // Utility functions ---------------------------------------- func readFileContent(path string) (string, error) { data, err := ioutil.ReadFile(path) if err != nil { return "", err } return string(data), nil } func parseMetaFile(zid id.Zid, path string) (*meta.Meta, error) { |
︙ | ︙ | |||
250 251 252 253 254 255 256 | return nil, "", err } inp := input.NewInput(src) meta := meta.NewFromInput(zid, inp) return meta, src[inp.Pos:], nil } | | > | > | < | > | > > > > > > > | > > > | 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | return nil, "", err } inp := input.NewInput(src) meta := meta.NewFromInput(zid, inp) return meta, src[inp.Pos:], nil } func cleanupMeta(m *meta.Meta, entry *directory.Entry) { if title, ok := m.Get(meta.KeyTitle); !ok || title == "" { m.Set(meta.KeyTitle, entry.Zid.String()) } if entry.MetaSpec == directory.MetaSpecFile { if syntax, ok := m.Get(meta.KeySyntax); !ok || syntax == "" { dm := entry.CalcDefaultMeta() syntax, ok = dm.Get(meta.KeySyntax) if !ok { panic("Default meta must contain syntax") } m.Set(meta.KeySyntax, syntax) } } if entry.Duplicates { m.Set(meta.KeyDuplicates, meta.ValueTrue) } } func openFileWrite(path string) (*os.File, error) { return os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) } func writeFileZid(f *os.File, zid id.Zid) error { |
︙ | ︙ |
Deleted place/fileplace/fileplace.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted place/fileplace/zipplace.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Added place/filter.go.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package place provides a generic interface to zettel places. package place import ( "strings" "zettelstore.de/z/domain/meta" ) // EnsureFilter make sure that there is a current filter. func EnsureFilter(filter *Filter) *Filter { if filter == nil { filter = new(Filter) filter.Expr = make(FilterExpr) } return filter } // FilterFunc is a predicate to check if given meta must be selected. type FilterFunc func(*meta.Meta) bool func selectAll(m *meta.Meta) bool { return true } type matchFunc func(value string) bool func matchNever(value string) bool { return false } type matchSpec struct { key string match matchFunc } // CreateFilterFunc calculates a filter func based on the given filter. func CreateFilterFunc(filter *Filter) FilterFunc { if filter == nil { return selectAll } specs, searchAll := createFilterSpecs(filter) if len(specs) == 0 { if searchAll == nil { if sel := filter.Select; sel != nil { return sel } return selectAll } return addSelectFunc(filter, searchAll) } negate := filter.Negate searchMeta := func(m *meta.Meta) bool { for _, s := range specs { value, ok := m.Get(s.key) if !ok || !s.match(value) { return negate } } return !negate } if searchAll == nil { return addSelectFunc(filter, searchMeta) } return addSelectFunc(filter, func(meta *meta.Meta) bool { return searchAll(meta) || searchMeta(meta) }) } func createFilterSpecs(filter *Filter) ([]matchSpec, FilterFunc) { specs := make([]matchSpec, 0, len(filter.Expr)) var searchAll FilterFunc for key, values := range filter.Expr { if key == "" { // Special handling if searching all keys... searchAll = createSearchAllFunc(values, filter.Negate) continue } if meta.KeyIsValid(key) { match := createMatchFunc(key, values) if match != nil { specs = append(specs, matchSpec{key, match}) } } } return specs, searchAll } func addSelectFunc(filter *Filter, f FilterFunc) FilterFunc { if filter == nil { return f } if sel := filter.Select; sel != nil { return func(meta *meta.Meta) bool { return sel(meta) && f(meta) } } return f } func createMatchFunc(key string, values []string) matchFunc { switch meta.Type(key) { case meta.TypeBool: return createMatchBoolFunc(values) case meta.TypeCredential: return matchNever case meta.TypeID, meta.TypeTimestamp: // ID and timestamp use the same layout return createMatchIDFunc(values) case meta.TypeIDSet: return createMatchIDSetFunc(values) case meta.TypeTagSet: return createMatchTagSetFunc(values) case meta.TypeWord: return createMatchWordFunc(values) case meta.TypeWordSet: return createMatchWordSetFunc(values) } return createMatchStringFunc(values) } func createMatchBoolFunc(values []string) matchFunc { preValues := make([]bool, 0, len(values)) for _, v := range values { preValues = append(preValues, meta.BoolValue(v)) } return func(value string) bool { bValue := meta.BoolValue(value) for _, v := range preValues { if bValue != v { return false } } return true } } func createMatchIDFunc(values []string) matchFunc { return func(value string) bool { for _, v := range values { if !strings.HasPrefix(value, v) { return false } } return true } } func createMatchIDSetFunc(values []string) matchFunc { idValues := preprocessSet(sliceToLower(values)) return func(value string) bool { ids := meta.ListFromValue(value) for _, neededIDs := range idValues { for _, neededID := range neededIDs { if !matchAllID(ids, neededID) { return false } } } return true } } func createMatchTagSetFunc(values []string) matchFunc { tagValues := preprocessSet(values) return func(value string) bool { tags := meta.ListFromValue(value) // Remove leading '#' from each tag for i, tag := range tags { tags[i] = meta.CleanTag(tag) } for _, neededTags := range tagValues { for _, neededTag := range neededTags { if !matchAllTag(tags, neededTag) { return false } } } return true } } func createMatchWordFunc(values []string) matchFunc { values = sliceToLower(values) return func(value string) bool { value = strings.ToLower(value) for _, v := range values { if value != v { return false } } return true } } func createMatchWordSetFunc(values []string) matchFunc { wordValues := preprocessSet(sliceToLower(values)) return func(value string) bool { words := meta.ListFromValue(value) for _, neededWords := range wordValues { for _, neededWord := range neededWords { if !matchAllWord(words, neededWord) { return false } } } return true } } func createMatchStringFunc(values []string) matchFunc { values = sliceToLower(values) return func(value string) bool { value = strings.ToLower(value) for _, v := range values { if !strings.Contains(value, v) { return false } } return true } } func createSearchAllFunc(values []string, negate bool) FilterFunc { matchFuncs := map[*meta.DescriptionType]matchFunc{} return func(m *meta.Meta) bool { for _, p := range m.Pairs(true) { keyType := meta.Type(p.Key) match, ok := matchFuncs[keyType] if !ok { if keyType == meta.TypeBool { match = createBoolSearchFunc(p.Key, values) } else { match = createMatchFunc(p.Key, values) } matchFuncs[keyType] = match } if match(p.Value) { return !negate } } match, ok := matchFuncs[meta.Type(meta.KeyID)] if !ok { match = createMatchFunc(meta.KeyID, values) } return match(m.Zid.String()) != negate } } // createBoolSearchFunc only creates a matchFunc if the values to compare are // possible bool values. Otherwise every meta with a bool key could match the // search query. func createBoolSearchFunc(key string, values []string) matchFunc { for _, v := range values { if len(v) > 0 && !strings.ContainsRune("01tfTFynYN", rune(v[0])) { return func(value string) bool { return false } } } return createMatchFunc(key, values) } func sliceToLower(sl []string) []string { result := make([]string, 0, len(sl)) for _, s := range sl { result = append(result, strings.ToLower(s)) } return result } func preprocessSet(set []string) [][]string { result := make([][]string, 0, len(set)) for _, elem := range set { splitElems := strings.Split(elem, ",") valueElems := make([]string, 0, len(splitElems)) for _, se := range splitElems { e := strings.TrimSpace(se) if len(e) > 0 { valueElems = append(valueElems, e) } } if len(valueElems) > 0 { result = append(result, valueElems) } } return result } func matchAllID(zettelIDs []string, neededID string) bool { for _, zt := range zettelIDs { if strings.HasPrefix(zt, neededID) { return true } } return false } func matchAllTag(zettelTags []string, neededTag string) bool { for _, zt := range zettelTags { if zt == neededTag { return true } } return false } func matchAllWord(zettelWords []string, neededWord string) bool { for _, zw := range zettelWords { if zw == neededWord { return true } } return false } |
Changes to place/manager/manager.go.
︙ | ︙ | |||
11 12 13 14 15 16 17 | // Package manager coordinates the various places of a Zettelstore. package manager import ( "context" "log" "net/url" | < < < < | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | // Package manager coordinates the various places of a Zettelstore. package manager import ( "context" "log" "net/url" "sort" "strings" "sync" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" "zettelstore.de/z/place" ) // ConnectData contains all administration related values. type ConnectData struct { Filter index.MetaFilter Notify chan<- place.ChangeInfo } // Connect returns a handle to the specified place func Connect(rawURL string, readonlyMode bool, cdata *ConnectData) (place.Place, error) { u, err := url.Parse(rawURL) if err != nil { return nil, err } if u.Scheme == "" { u.Scheme = "dir" } |
︙ | ︙ | |||
65 66 67 68 69 70 71 | } // ErrInvalidScheme is returned if there is no place with the given scheme type ErrInvalidScheme struct{ Scheme string } func (err *ErrInvalidScheme) Error() string { return "Invalid scheme: " + err.Scheme } | | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | } // ErrInvalidScheme is returned if there is no place with the given scheme type ErrInvalidScheme struct{ Scheme string } func (err *ErrInvalidScheme) Error() string { return "Invalid scheme: " + err.Scheme } type createFunc func(*url.URL, *ConnectData) (place.Place, error) var registry = map[string]createFunc{} // Register the encoder for later retrieval. func Register(scheme string, create createFunc) { if _, ok := registry[scheme]; ok { log.Fatalf("Place with scheme %q already registered", scheme) |
︙ | ︙ | |||
91 92 93 94 95 96 97 | return result } // Manager is a coordinating place. type Manager struct { mx sync.RWMutex started bool | | | | | | < | < | | | | < < | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | return result } // Manager is a coordinating place. type Manager struct { mx sync.RWMutex started bool subplaces []place.Place filter index.MetaFilter observers []func(place.ChangeInfo) mxObserver sync.RWMutex done chan struct{} infos chan place.ChangeInfo } // New creates a new managing place. func New(placeURIs []string, readonlyMode bool, filter index.MetaFilter) (*Manager, error) { mgr := &Manager{ filter: filter, infos: make(chan place.ChangeInfo, len(placeURIs)*10), } cdata := ConnectData{Filter: filter, Notify: mgr.infos} subplaces := make([]place.Place, 0, len(placeURIs)+2) for _, uri := range placeURIs { p, err := Connect(uri, readonlyMode, &cdata) if err != nil { return nil, err } subplaces = append(subplaces, p) } constplace, err := registry[" const"](nil, &cdata) if err != nil { return nil, err } progplace, err := registry[" prog"](nil, &cdata) if err != nil { return nil, err } subplaces = append(subplaces, constplace, progplace) mgr.subplaces = subplaces return mgr, nil } // RegisterObserver registers an observer that will be notified // if a zettel was found to be changed. func (mgr *Manager) RegisterObserver(f func(place.ChangeInfo)) { if f != nil { mgr.mxObserver.Lock() mgr.observers = append(mgr.observers, f) mgr.mxObserver.Unlock() } } func (mgr *Manager) notifyObserver(ci place.ChangeInfo) { mgr.mxObserver.RLock() observers := mgr.observers mgr.mxObserver.RUnlock() for _, ob := range observers { ob(ci) } } func notifier(notify func(place.ChangeInfo), infos <-chan place.ChangeInfo, done <-chan struct{}) { // The call to notify may panic. Ensure a running notifier. defer func() { if err := recover(); err != nil { go notifier(notify, infos, done) } }() for { select { case ci, ok := <-infos: |
︙ | ︙ | |||
216 217 218 219 220 221 222 | mgr.mx.Unlock() return err } mgr.done = make(chan struct{}) go notifier(mgr.notifyObserver, mgr.infos, mgr.done) mgr.started = true mgr.mx.Unlock() | | | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | mgr.mx.Unlock() return err } mgr.done = make(chan struct{}) go notifier(mgr.notifyObserver, mgr.infos, mgr.done) mgr.started = true mgr.mx.Unlock() mgr.infos <- place.ChangeInfo{Reason: place.OnReload, Zid: id.Invalid} return nil } // Stop the started place. Now only the Start() function is allowed. func (mgr *Manager) Stop(ctx context.Context) error { mgr.mx.Lock() defer mgr.mx.Unlock() |
︙ | ︙ | |||
267 268 269 270 271 272 273 | mgr.mx.RLock() defer mgr.mx.RUnlock() if !mgr.started { return domain.Zettel{}, place.ErrStopped } for _, p := range mgr.subplaces { if z, err := p.GetZettel(ctx, zid); err != place.ErrNotFound { | < | < < | < | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | mgr.mx.RLock() defer mgr.mx.RUnlock() if !mgr.started { return domain.Zettel{}, place.ErrStopped } for _, p := range mgr.subplaces { if z, err := p.GetZettel(ctx, zid); err != place.ErrNotFound { mgr.filter.Enrich(ctx, z.Meta) return z, err } } return domain.Zettel{}, place.ErrNotFound } // GetMeta retrieves just the meta data of a specific zettel. func (mgr *Manager) GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) { mgr.mx.RLock() defer mgr.mx.RUnlock() if !mgr.started { return nil, place.ErrStopped } for _, p := range mgr.subplaces { if m, err := p.GetMeta(ctx, zid); err != place.ErrNotFound { mgr.filter.Enrich(ctx, m) return m, err } } return nil, place.ErrNotFound } // FetchZids returns the set of all zettel identifer managed by the place. |
︙ | ︙ | |||
324 325 326 327 328 329 330 | } } return result, nil } // SelectMeta returns all zettel meta data that match the selection // criteria. The result is ordered by descending zettel id. | | < | < | | 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | } } return result, nil } // SelectMeta returns all zettel meta data that match the selection // criteria. The result is ordered by descending zettel id. func (mgr *Manager) SelectMeta(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) { mgr.mx.RLock() defer mgr.mx.RUnlock() if !mgr.started { return nil, place.ErrStopped } var result []*meta.Meta for _, p := range mgr.subplaces { selected, err := p.SelectMeta(ctx, f, nil) if err != nil { return nil, err } if len(result) == 0 { result = selected } else { result = place.MergeSorted(result, selected) } } if s == nil { return result, nil } return place.ApplySorter(result, s), nil } // CanUpdateZettel returns true, if place could possibly update the given zettel. func (mgr *Manager) CanUpdateZettel(ctx context.Context, zettel domain.Zettel) bool { mgr.mx.RLock() defer mgr.mx.RUnlock() return mgr.started && mgr.subplaces[0].CanUpdateZettel(ctx, zettel) |
︙ | ︙ |
Changes to place/memplace/memplace.go.
︙ | ︙ | |||
17 18 19 20 21 22 23 | "sync" "time" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" | < < | | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | "sync" "time" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" "zettelstore.de/z/place/manager" ) func init() { manager.Register( "mem", func(u *url.URL, cdata *manager.ConnectData) (place.Place, error) { return &memPlace{u: u, cdata: *cdata}, nil }) } type memPlace struct { u *url.URL cdata manager.ConnectData zettel map[id.Zid]domain.Zettel mx sync.RWMutex } func (mp *memPlace) notifyChanged(reason place.ChangeReason, zid id.Zid) { if chci := mp.cdata.Notify; chci != nil { chci <- place.ChangeInfo{Reason: reason, Zid: zid} } } func (mp *memPlace) Location() string { return mp.u.String() } |
︙ | ︙ | |||
70 71 72 73 74 75 76 | func (mp *memPlace) CreateZettel(ctx context.Context, zettel domain.Zettel) (id.Zid, error) { mp.mx.Lock() meta := zettel.Meta.Clone() meta.Zid = mp.calcNewZid() zettel.Meta = meta mp.zettel[meta.Zid] = zettel mp.mx.Unlock() | | | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | func (mp *memPlace) CreateZettel(ctx context.Context, zettel domain.Zettel) (id.Zid, error) { mp.mx.Lock() meta := zettel.Meta.Clone() meta.Zid = mp.calcNewZid() zettel.Meta = meta mp.zettel[meta.Zid] = zettel mp.mx.Unlock() mp.notifyChanged(place.OnUpdate, meta.Zid) return meta.Zid, nil } func (mp *memPlace) calcNewZid() id.Zid { zid := id.New(false) if _, ok := mp.zettel[zid]; !ok { return zid |
︙ | ︙ | |||
119 120 121 122 123 124 125 | for zid := range mp.zettel { result[zid] = true } mp.mx.RUnlock() return result, nil } | | > | | | | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | for zid := range mp.zettel { result[zid] = true } mp.mx.RUnlock() return result, nil } func (mp *memPlace) SelectMeta(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) { filterFunc := place.CreateFilterFunc(f) result := make([]*meta.Meta, 0, len(mp.zettel)) mp.mx.RLock() for _, zettel := range mp.zettel { m := zettel.Meta.Clone() mp.cdata.Filter.Enrich(ctx, m) if filterFunc(m) { result = append(result, m) } } mp.mx.RUnlock() return place.ApplySorter(result, s), nil } func (mp *memPlace) CanUpdateZettel(ctx context.Context, zettel domain.Zettel) bool { return true } func (mp *memPlace) UpdateZettel(ctx context.Context, zettel domain.Zettel) error { mp.mx.Lock() meta := zettel.Meta.Clone() if !meta.Zid.IsValid() { return &place.ErrInvalidID{Zid: meta.Zid} } zettel.Meta = meta mp.zettel[meta.Zid] = zettel mp.mx.Unlock() mp.notifyChanged(place.OnUpdate, meta.Zid) return nil } func (mp *memPlace) AllowRenameZettel(ctx context.Context, zid id.Zid) bool { return true } func (mp *memPlace) RenameZettel(ctx context.Context, curZid, newZid id.Zid) error { mp.mx.Lock() |
︙ | ︙ | |||
172 173 174 175 176 177 178 | meta := zettel.Meta.Clone() meta.Zid = newZid zettel.Meta = meta mp.zettel[newZid] = zettel delete(mp.zettel, curZid) mp.mx.Unlock() | | | | | 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | meta := zettel.Meta.Clone() meta.Zid = newZid zettel.Meta = meta mp.zettel[newZid] = zettel delete(mp.zettel, curZid) mp.mx.Unlock() mp.notifyChanged(place.OnDelete, curZid) mp.notifyChanged(place.OnUpdate, newZid) return nil } func (mp *memPlace) CanDeleteZettel(ctx context.Context, zid id.Zid) bool { mp.mx.RLock() _, ok := mp.zettel[zid] mp.mx.RUnlock() return ok } func (mp *memPlace) DeleteZettel(ctx context.Context, zid id.Zid) error { mp.mx.Lock() if _, ok := mp.zettel[zid]; !ok { mp.mx.Unlock() return place.ErrNotFound } delete(mp.zettel, zid) mp.mx.Unlock() mp.notifyChanged(place.OnDelete, zid) return nil } func (mp *memPlace) ReadStats(st *place.Stats) { st.ReadOnly = false mp.mx.RLock() st.Zettel = len(mp.zettel) mp.mx.RUnlock() } |
Changes to place/merge.go.
1 | //----------------------------------------------------------------------------- | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package place provides a generic interface to zettel places. package place import "zettelstore.de/z/domain/meta" // MergeSorted returns a merged sequence of meta data, sorted by a given Sorter. // The lists first and second must be sorted descending by Zid. func MergeSorted(first, second []*meta.Meta) []*meta.Meta { lenFirst := len(first) lenSecond := len(second) result := make([]*meta.Meta, 0, lenFirst+lenSecond) iFirst := 0 iSecond := 0 |
︙ | ︙ |
Changes to place/place.go.
︙ | ︙ | |||
15 16 17 18 19 20 21 | "context" "errors" "fmt" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" | < < | | > > > > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | "context" "errors" "fmt" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" ) // Place is implemented by all Zettel places. type Place interface { // Location returns some information where the place is located. // Format is dependent of the place. Location() string // CanCreateZettel returns true, if place could possibly create a new zettel. CanCreateZettel(ctx context.Context) bool // CreateZettel creates a new zettel. // Returns the new zettel id (and an error indication). CreateZettel(ctx context.Context, zettel domain.Zettel) (id.Zid, error) // GetZettel retrieves a specific zettel. GetZettel(ctx context.Context, zid id.Zid) (domain.Zettel, error) // GetMeta retrieves just the meta data of a specific zettel. GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) // FetchZids returns the set of all zettel identifer managed by the place. FetchZids(ctx context.Context) (id.Set, error) // SelectMeta returns all zettel meta data that match the selection criteria. // TODO: more docs SelectMeta(ctx context.Context, f *Filter, s *Sorter) ([]*meta.Meta, error) // CanUpdateZettel returns true, if place could possibly update the given zettel. CanUpdateZettel(ctx context.Context, zettel domain.Zettel) bool // UpdateZettel updates an existing zettel. UpdateZettel(ctx context.Context, zettel domain.Zettel) error |
︙ | ︙ | |||
63 64 65 66 67 68 69 | // DeleteZettel removes the zettel from the place. DeleteZettel(ctx context.Context, zid id.Zid) error // ReadStats populates st with place statistics ReadStats(st *Stats) } | < < < < < < < < | | | > > > > > > | | < > > > > | > > > | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | // DeleteZettel removes the zettel from the place. DeleteZettel(ctx context.Context, zid id.Zid) error // ReadStats populates st with place statistics ReadStats(st *Stats) } // Stats records statistics about the place. type Stats struct { // ReadOnly indicates that the places cannot be changed ReadOnly bool // Zettel is the number of zettel managed by the place. Zettel int } // StartStopper performs simple lifecycle management. type StartStopper interface { // Start the place. Now all other functions of the place are allowed. // Starting an already started place is not allowed. Start(ctx context.Context) error // Stop the started place. Now only the Start() function is allowed. Stop(ctx context.Context) error } // ChangeReason gives an indication, why the ObserverFunc was called. type ChangeReason int // Values for ChangeReason const ( _ ChangeReason = iota OnReload // Place was reloaded OnUpdate // A zettel was created or changed OnDelete // A zettel was removed ) // ChangeInfo contains all the data about a changed zettel. type ChangeInfo struct { Reason ChangeReason Zid id.Zid } // Manager is a place-managing place. type Manager interface { Place StartStopper // RegisterObserver registers an observer that will be notified // if one or all zettel are found to be changed. RegisterObserver(func(ChangeInfo)) // NumPlaces returns the number of managed places. NumPlaces() int } // ErrNotAllowed is returned if the caller is not allowed to perform the operation. type ErrNotAllowed struct { |
︙ | ︙ | |||
171 172 173 174 175 176 177 | // ErrNotFound is returned if a zettel was not found in the place. var ErrNotFound = errors.New("zettel not found") // ErrInvalidID is returned if the zettel id is not appropriate for the place operation. type ErrInvalidID struct{ Zid id.Zid } func (err *ErrInvalidID) Error() string { return "invalid Zettel id: " + err.Zid.String() } | > > > > > > > > > > > > > > > > > > | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | // ErrNotFound is returned if a zettel was not found in the place. var ErrNotFound = errors.New("zettel not found") // ErrInvalidID is returned if the zettel id is not appropriate for the place operation. type ErrInvalidID struct{ Zid id.Zid } func (err *ErrInvalidID) Error() string { return "invalid Zettel id: " + err.Zid.String() } // Filter specifies a mechanism for selecting zettel. type Filter struct { Expr FilterExpr Negate bool Select func(*meta.Meta) bool } // FilterExpr is the encoding of a search filter. type FilterExpr map[string][]string // map of keys to or-ed values // Sorter specifies ordering and limiting a sequnce of meta data. type Sorter struct { Order string // Name of meta key. None given: use "id" Descending bool // Sort by order, but descending Offset int // <= 0: no offset Limit int // <= 0: no limit } |
Changes to place/progplace/indexer.go.
︙ | ︙ | |||
39 40 41 42 43 44 45 | var sb strings.Builder sb.WriteString("|=Name|=Value>\n") fmt.Fprintf(&sb, "|Zettel| %v\n", stats.Store.Zettel) fmt.Fprintf(&sb, "|Last re-index| %v\n", stats.LastReload.Format("2006-01-02 15:04:05 -0700 MST")) fmt.Fprintf(&sb, "|Indexes since last re-index| %v\n", stats.IndexesSinceReload) fmt.Fprintf(&sb, "|Duration last index| %vms\n", stats.DurLastIndex.Milliseconds()) fmt.Fprintf(&sb, "|Zettel enrichments| %v\n", stats.Store.Updates) | < | 39 40 41 42 43 44 45 46 47 | var sb strings.Builder sb.WriteString("|=Name|=Value>\n") fmt.Fprintf(&sb, "|Zettel| %v\n", stats.Store.Zettel) fmt.Fprintf(&sb, "|Last re-index| %v\n", stats.LastReload.Format("2006-01-02 15:04:05 -0700 MST")) fmt.Fprintf(&sb, "|Indexes since last re-index| %v\n", stats.IndexesSinceReload) fmt.Fprintf(&sb, "|Duration last index| %vms\n", stats.DurLastIndex.Milliseconds()) fmt.Fprintf(&sb, "|Zettel enrichments| %v\n", stats.Store.Updates) return sb.String() } |
Changes to place/progplace/progplace.go.
︙ | ︙ | |||
18 19 20 21 22 23 24 | "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" "zettelstore.de/z/place" "zettelstore.de/z/place/manager" | < | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" "zettelstore.de/z/place" "zettelstore.de/z/place/manager" ) func init() { manager.Register( " prog", func(u *url.URL, cdata *manager.ConnectData) (place.Place, error) { return getPlace(cdata.Filter), nil }) } type ( zettelGen struct { meta func(id.Zid) *meta.Meta |
︙ | ︙ | |||
47 48 49 50 51 52 53 | indexer index.Indexer } ) var myPlace *progPlace // Get returns the one program place. | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | indexer index.Indexer } ) var myPlace *progPlace // Get returns the one program place. func getPlace(mf index.MetaFilter) place.Place { if myPlace == nil { myPlace = &progPlace{ zettel: map[id.Zid]zettelGen{ id.Zid(1): {genVersionBuildM, genVersionBuildC}, id.Zid(2): {genVersionHostM, genVersionHostC}, id.Zid(3): {genVersionOSM, genVersionOSC}, id.Zid(6): {genEnvironmentM, genEnvironmentC}, |
︙ | ︙ | |||
90 91 92 93 94 95 96 | func (pp *progPlace) CanCreateZettel(ctx context.Context) bool { return false } func (pp *progPlace) CreateZettel( ctx context.Context, zettel domain.Zettel) (id.Zid, error) { return id.Invalid, place.ErrReadOnly } | > | | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | func (pp *progPlace) CanCreateZettel(ctx context.Context) bool { return false } func (pp *progPlace) CreateZettel( ctx context.Context, zettel domain.Zettel) (id.Zid, error) { return id.Invalid, place.ErrReadOnly } func (pp *progPlace) GetZettel( ctx context.Context, zid id.Zid) (domain.Zettel, error) { if gen, ok := pp.zettel[zid]; ok && gen.meta != nil { if m := gen.meta(zid); m != nil { updateMeta(m) if genContent := gen.content; genContent != nil { return domain.Zettel{ Meta: m, Content: domain.NewContent(genContent(m)), |
︙ | ︙ | |||
130 131 132 133 134 135 136 | result[zid] = true } } } return result, nil } | | > > | | | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | result[zid] = true } } } return result, nil } func (pp *progPlace) SelectMeta( ctx context.Context, f *place.Filter, s *place.Sorter) (res []*meta.Meta, err error) { hasMatch := place.CreateFilterFunc(f) for zid, gen := range pp.zettel { if genMeta := gen.meta; genMeta != nil { if m := genMeta(zid); m != nil { updateMeta(m) pp.filter.Enrich(ctx, m) if hasMatch(m) { res = append(res, m) } } } } return place.ApplySorter(res, s), nil } func (pp *progPlace) CanUpdateZettel(ctx context.Context, zettel domain.Zettel) bool { return false } func (pp *progPlace) UpdateZettel(ctx context.Context, zettel domain.Zettel) error { |
︙ | ︙ | |||
180 181 182 183 184 185 186 | func (pp *progPlace) ReadStats(st *place.Stats) { st.ReadOnly = true st.Zettel = len(pp.zettel) } func updateMeta(m *meta.Meta) { | < | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | func (pp *progPlace) ReadStats(st *place.Stats) { st.ReadOnly = true st.Zettel = len(pp.zettel) } func updateMeta(m *meta.Meta) { m.Set(meta.KeySyntax, meta.ValueSyntaxZmk) m.Set(meta.KeyRole, meta.ValueRoleConfiguration) m.Set(meta.KeyReadOnly, meta.ValueTrue) if _, ok := m.Get(meta.KeyVisibility); !ok { m.Set(meta.KeyVisibility, meta.ValueVisibilityExpert) } } |
Changes to place/progplace/runtime.go.
︙ | ︙ | |||
9 10 11 12 13 14 15 | //----------------------------------------------------------------------------- // Package progplace provides zettel that inform the user about the internal Zettelstore state. package progplace import ( "fmt" | | > | < < < < < < < < < < < < < > > > | < < < < < > | < < < < > > | < | < < < < < > > > > | < < < > > > > > > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | //----------------------------------------------------------------------------- // Package progplace provides zettel that inform the user about the internal Zettelstore state. package progplace import ( "fmt" "runtime" "strings" "time" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" ) func genRuntimeM(zid id.Zid) *meta.Meta { if myPlace.startConfig == nil { return nil } m := meta.New(zid) m.Set(meta.KeyTitle, "Zettelstore Runtime Values") return m } func genRuntimeC(*meta.Meta) string { var sb strings.Builder sb.WriteString("|=Name|=Value>\n") fmt.Fprintf(&sb, "|Number of CPUs|%v\n", runtime.NumCPU()) fmt.Fprintf(&sb, "|Number of goroutines|%v\n", runtime.NumGoroutine()) fmt.Fprintf(&sb, "|Number of Cgo calls|%v\n", runtime.NumCgoCall()) var m runtime.MemStats runtime.ReadMemStats(&m) fmt.Fprintf(&sb, "|Memory from OS|%v\n", m.Sys) fmt.Fprintf(&sb, "|Objects active|%v\n", m.Mallocs-m.Frees) fmt.Fprintf(&sb, "|Heap alloc|%v\n", m.HeapAlloc) fmt.Fprintf(&sb, "|Heap sys|%v\n", m.HeapSys) fmt.Fprintf(&sb, "|Heap idle|%v\n", m.HeapIdle) fmt.Fprintf(&sb, "|Heap in use|%v\n", m.HeapInuse) fmt.Fprintf(&sb, "|Heap released|%v\n", m.HeapReleased) fmt.Fprintf(&sb, "|Heap objects|%v\n", m.HeapObjects) fmt.Fprintf(&sb, "|Stack in use|%v\n", m.StackInuse) fmt.Fprintf(&sb, "|Stack sys|%v\n", m.StackSys) fmt.Fprintf(&sb, "|Garbage collection metadata|%v\n", m.GCSys) fmt.Fprintf(&sb, "|Last garbage collection|%v\n", time.Unix((int64)(m.LastGC/1000000000), 0)) fmt.Fprintf(&sb, "|Garbage collection goal|%v\n", m.NextGC) fmt.Fprintf(&sb, "|Garbage collections|%v\n", m.NumGC) fmt.Fprintf(&sb, "|Forced garbage collections|%v\n", m.NumForcedGC) fmt.Fprintf(&sb, "|Garbage collection fraction|%.3f%%\n", m.GCCPUFraction*100.0) return sb.String() } |
Added place/sorter.go.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package place provides a generic interface to zettel places. package place import ( "math/rand" "sort" "strconv" "zettelstore.de/z/domain/meta" ) // RandomOrder is a pseudo metadata key that selects a random order. const RandomOrder = "_random" // EnsureSorter makes sure that there is a sorter object. func EnsureSorter(sorter *Sorter) *Sorter { if sorter == nil { sorter = new(Sorter) } return sorter } // ApplySorter applies the given sorter to the slide of meta data. func ApplySorter(metaList []*meta.Meta, s *Sorter) []*meta.Meta { if len(metaList) == 0 { return metaList } if s == nil { sort.Slice( metaList, func(i, j int) bool { return metaList[i].Zid > metaList[j].Zid }) return metaList } if s.Order == "" { sort.Slice(metaList, createSortFunc(meta.KeyID, true, metaList)) } else if s.Order == RandomOrder { rand.Shuffle(len(metaList), func(i, j int) { metaList[i], metaList[j] = metaList[j], metaList[i] }) } else { sort.Slice(metaList, createSortFunc(s.Order, s.Descending, metaList)) } if s.Offset > 0 { if s.Offset > len(metaList) { return nil } metaList = metaList[s.Offset:] } if s.Limit > 0 && s.Limit < len(metaList) { metaList = metaList[:s.Limit] } return metaList } type sortFunc func(i, j int) bool func createSortFunc(key string, descending bool, ml []*meta.Meta) sortFunc { keyType := meta.Type(key) if key == meta.KeyID || keyType == meta.TypeCredential { if descending { return func(i, j int) bool { return ml[i].Zid > ml[j].Zid } } return func(i, j int) bool { return ml[i].Zid < ml[j].Zid } } if keyType == meta.TypeBool { return createSortBoolFunc(ml, key, descending) } if keyType == meta.TypeNumber { return createSortNumberFunc(ml, key, descending) } return createSortStringFunc(ml, key, descending) } func createSortBoolFunc(ml []*meta.Meta, key string, descending bool) sortFunc { if descending { return func(i, j int) bool { left := ml[i].GetBool(key) if left == ml[j].GetBool(key) { return i > j } return left } } return func(i, j int) bool { right := ml[j].GetBool(key) if ml[i].GetBool(key) == right { return i < j } return right } } func createSortNumberFunc(ml []*meta.Meta, key string, descending bool) sortFunc { if descending { return func(i, j int) bool { iVal, iOk := getNum(ml[i], key) jVal, jOk := getNum(ml[j], key) return (iOk && (!jOk || iVal > jVal)) || !jOk } } return func(i, j int) bool { iVal, iOk := getNum(ml[i], key) jVal, jOk := getNum(ml[j], key) return (iOk && (!jOk || iVal < jVal)) || !jOk } } func createSortStringFunc(ml []*meta.Meta, key string, descending bool) sortFunc { if descending { return func(i, j int) bool { iVal, iOk := ml[i].Get(key) jVal, jOk := ml[j].Get(key) return (iOk && (!jOk || iVal > jVal)) || !jOk } } return func(i, j int) bool { iVal, iOk := ml[i].Get(key) jVal, jOk := ml[j].Get(key) return (iOk && (!jOk || iVal < jVal)) || !jOk } } func getNum(m *meta.Meta, key string) (int, bool) { if s, ok := m.Get(key); ok { if i, err := strconv.Atoi(s); err == nil { return i, true } } return 0, false } |
Changes to place/stock/stock.go.
︙ | ︙ | |||
14 15 16 17 18 19 20 | import ( "context" "sync" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" | | > | > > | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import ( "context" "sync" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" ) // Place is a place that is used by a stock. type Place interface { // RegisterObserver registers an observer that will be notified // if all or one zettel are found to be changed. RegisterObserver(ob func(place.ChangeInfo)) // GetZettel retrieves a specific zettel. GetZettel(ctx context.Context, zid id.Zid) (domain.Zettel, error) } // Stock allow to get subscribed zettel without reading it from a place. type Stock interface { Subscribe(zid id.Zid) error GetZettel(zid id.Zid) domain.Zettel GetMeta(zid id.Zid) *meta.Meta } // NewStock creates a new stock that operates on the given place. func NewStock(place Place) Stock { //RegisterChangeObserver(func(domain.Zid)) stock := &defaultStock{ place: place, subs: make(map[id.Zid]domain.Zettel), } place.RegisterObserver(stock.observe) return stock } type defaultStock struct { place Place subs map[id.Zid]domain.Zettel mxSubs sync.RWMutex } // observe tracks all changes the place signals. func (s *defaultStock) observe(ci place.ChangeInfo) { if ci.Reason == place.OnReload { go func() { s.mxSubs.Lock() defer s.mxSubs.Unlock() for zid := range s.subs { s.update(zid) } }() |
︙ | ︙ |
Deleted search/filter.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted search/print.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted search/search.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted search/selector.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted search/sorter.go.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted staticcheck.conf.
|
| < < |
Changes to strfun/slugify.go.
1 | //----------------------------------------------------------------------------- | | > > < < < < < < < < < < < < < < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package strfun provides some string functions. package strfun import ( "strings" "unicode" "golang.org/x/text/unicode/norm" ) var ( useUnicode = []*unicode.RangeTable{ unicode.Letter, unicode.Number, } ignoreUnicode = []*unicode.RangeTable{ unicode.Mark, unicode.Sk, unicode.Lm, } ) // Slugify returns a string that can be used as part of an URL func Slugify(s string) string { s = strings.TrimSpace(s) result := make([]rune, 0, len(s)) addDash := false for _, r := range norm.NFKD.String(s) { if unicode.IsOneOf(useUnicode, r) { result = append(result, unicode.ToLower(r)) addDash = true } else if !unicode.IsOneOf(ignoreUnicode, r) && addDash { result = append(result, '-') addDash = false } } if i := len(result) - 1; i >= 0 && result[i] == '-' { result = result[:i] } return string(result) } |
Changes to strfun/slugify_test.go.
1 | //----------------------------------------------------------------------------- | | < | | | | | | | | | > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package strfun provides some string functions. package strfun_test import ( "testing" "zettelstore.de/z/strfun" ) var tests = []struct{ in, exp string }{ {"simple test", "simple-test"}, {"I'm a go developer", "i-m-a-go-developer"}, {"-!->simple test<-!-", "simple-test"}, {"äöüÄÖÜß", "aouaouß"}, {"\"aèf", "aef"}, {"a#b", "a-b"}, {"*", ""}, } func TestSlugify(t *testing.T) { for _, test := range tests { if got := strfun.Slugify(test.in); got != test.exp { t.Errorf("%q: %q != %q", test.in, got, test.exp) } } } |
Changes to template/mustache.go.
︙ | ︙ | |||
14 15 16 17 18 19 20 | // Starting with commit [f9b4cbf] // Does not have an explicit copyright and obviously continues with // above MIT license. // The license text is included in the same directory where this file is // located. See file LICENSE. //----------------------------------------------------------------------------- | < | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | // Starting with commit [f9b4cbf] // Does not have an explicit copyright and obviously continues with // above MIT license. // The license text is included in the same directory where this file is // located. See file LICENSE. //----------------------------------------------------------------------------- package template import ( "fmt" "io" "reflect" "regexp" |
︙ | ︙ | |||
260 261 262 263 264 265 266 | for i := tmpl.p; i < len(tmpl.data); i++ { if !(tmpl.data[i] == ' ' || tmpl.data[i] == '\t') { eow = i break } } | > > | > > > > > > > > > > > > > > > > > > > > < < < < < < < < < < < < < < < < < < < < < < < < < < | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | for i := tmpl.p; i < len(tmpl.data); i++ { if !(tmpl.data[i] == ' ' || tmpl.data[i] == '\t') { eow = i break } } // Skip all whitespaces apeared after these types of tags until end of line if // the line only contains a tag and whitespaces. standalone := true if mayStandalone { if _, ok := skipWhitespaceTagTypes[tag[0]]; !ok { standalone = false } else { if eow == len(tmpl.data) { standalone = true tmpl.p = eow } else if eow < len(tmpl.data) && tmpl.data[eow] == '\n' { standalone = true tmpl.p = eow + 1 tmpl.curline++ } else if eow+1 < len(tmpl.data) && tmpl.data[eow] == '\r' && tmpl.data[eow+1] == '\n' { standalone = true tmpl.p = eow + 2 tmpl.curline++ } else { standalone = false } } } return &tagReadingResult{ tag: tag, standalone: standalone, }, nil } func (tmpl *Template) parsePartial(name, indent string) (*partialNode, error) { return &partialNode{ name: name, indent: indent, prov: tmpl.partial, }, nil } |
︙ | ︙ | |||
460 461 462 463 464 465 466 467 | v, err := lookup(stack, name[:pos], errMissing) if err != nil { return v, err } return lookup([]reflect.Value{v}, name[pos+1:], errMissing) } for i := len(stack) - 1; i >= 0; i-- { | > | > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | v, err := lookup(stack, name[:pos], errMissing) if err != nil { return v, err } return lookup([]reflect.Value{v}, name[pos+1:], errMissing) } Outer: for i := len(stack) - 1; i >= 0; i-- { v := stack[i] for v.IsValid() { typ := v.Type() if n := v.Type().NumMethod(); n > 0 { for i := 0; i < n; i++ { m := typ.Method(i) mtyp := m.Type if m.Name == name && mtyp.NumIn() == 1 { return v.Method(i).Call(nil)[0], nil } } } if name == "." { return v, nil } switch av := v; av.Kind() { case reflect.Ptr: v = av.Elem() case reflect.Interface: v = av.Elem() case reflect.Struct: ret := av.FieldByName(name) if ret.IsValid() { return ret, nil } continue Outer case reflect.Map: ret := av.MapIndex(reflect.ValueOf(name)) if ret.IsValid() { return ret, nil } continue Outer default: continue Outer } } } if errMissing { return reflect.Value{}, fmt.Errorf("missing variable %q", name) } return reflect.Value{}, nil } func isEmpty(v reflect.Value) bool { if !v.IsValid() || v.Interface() == nil { return true } valueInd := indirect(v) if !valueInd.IsValid() { |
︙ | ︙ | |||
549 550 551 552 553 554 555 | func (tmpl *Template) renderSection(w io.Writer, section *sectionNode, stack []reflect.Value) error { value, err := lookup(stack, section.name, false) if err != nil { return err } | | | > | | > > | | > | < | | | < | < < | | 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | func (tmpl *Template) renderSection(w io.Writer, section *sectionNode, stack []reflect.Value) error { value, err := lookup(stack, section.name, false) if err != nil { return err } // if the value is nil, check if it's an inverted section isEmpty := isEmpty(value) if isEmpty && !section.inverted || !isEmpty && section.inverted { return nil } if !section.inverted { switch val := indirect(value); val.Kind() { case reflect.Slice, reflect.Array: valLen := val.Len() enumeration := make([]reflect.Value, 0, valLen) for i := 0; i < valLen; i++ { enumeration = append(enumeration, val.Index(i)) } topStack := len(stack) stack = append(stack, enumeration[0]) defer func() { stack = stack[:topStack-1] }() for _, elem := range enumeration { stack[topStack] = elem for _, n := range section.nodes { if err := tmpl.renderNode(w, n, stack); err != nil { return err } } } return nil case reflect.Map, reflect.Struct: stack = append(stack, value) defer func() { stack = stack[:len(stack)-2] }() } } for _, n := range section.nodes { if err := tmpl.renderNode(w, n, stack); err != nil { return err } } return nil } |
︙ | ︙ |
Changes to template/mustache_test.go.
︙ | ︙ | |||
304 305 306 307 308 309 310 311 312 313 314 315 316 317 | t.Errorf("%q expected %q got %q", test.tmpl, test.expected, output) } else { t.Errorf("%q expected error %q but got %q", test.tmpl, test.err.Error(), output) } } } } type Person struct { FirstName string LastName string } func (p *Person) Name1() string { | > > > > > > > > > > > > > > > | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | t.Errorf("%q expected %q got %q", test.tmpl, test.expected, output) } else { t.Errorf("%q expected error %q but got %q", test.tmpl, test.err.Error(), output) } } } } type LayoutTest struct { layout string tmpl string context interface{} expected string } var layoutTests = []LayoutTest{ {`Header {{content}} Footer`, `Hello World`, nil, `Header Hello World Footer`}, {`Header {{content}} Footer`, `Hello {{s}}`, map[string]string{"s": "World"}, `Header Hello World Footer`}, {`Header {{content}} Footer`, `Hello {{content}}`, map[string]string{"content": "World"}, `Header Hello World Footer`}, {`Header {{extra}} {{content}} Footer`, `Hello {{content}}`, map[string]string{"content": "World", "extra": "extra"}, `Header extra Hello World Footer`}, {`Header {{content}} {{content}} Footer`, `Hello {{content}}`, map[string]string{"content": "World"}, `Header Hello World Hello World Footer`}, } type Person struct { FirstName string LastName string } func (p *Person) Name1() string { |
︙ | ︙ |
Changes to template/spec_test.go.
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 | // located. See file LICENSE. //----------------------------------------------------------------------------- package template_test import ( "encoding/json" "os" "path/filepath" "sort" "testing" "zettelstore.de/z/template" ) | > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | // located. See file LICENSE. //----------------------------------------------------------------------------- package template_test import ( "encoding/json" "io/ioutil" "os" "path/filepath" "sort" "testing" "zettelstore.de/z/template" ) |
︙ | ︙ | |||
201 202 203 204 205 206 207 | if !ok { t.Errorf("Unexpected file %s, consider adding to enabledFiles", file) continue } if enabled == nil { continue } | | | 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | if !ok { t.Errorf("Unexpected file %s, consider adding to enabledFiles", file) continue } if enabled == nil { continue } b, err := ioutil.ReadFile(path) if err != nil { t.Fatal(err) } var suite specTestSuite err = json.Unmarshal(b, &suite) if err != nil { t.Fatal(err) |
︙ | ︙ |
Changes to tests/markdown_test.go.
︙ | ︙ | |||
10 11 12 13 14 15 16 | // Package tests provides some higher-level tests. package tests import ( "encoding/json" "fmt" | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // Package tests provides some higher-level tests. package tests import ( "encoding/json" "fmt" "io/ioutil" "regexp" "strings" "testing" "zettelstore.de/z/ast" "zettelstore.de/z/encoder" _ "zettelstore.de/z/encoder/htmlenc" |
︙ | ︙ | |||
66 67 68 69 70 71 72 | } var reHeadingID = regexp.MustCompile(` id="[^"]*"`) func TestEncoderAvailability(t *testing.T) { encoderMissing := false for _, format := range formats { | | | | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | } var reHeadingID = regexp.MustCompile(` id="[^"]*"`) func TestEncoderAvailability(t *testing.T) { encoderMissing := false for _, format := range formats { enc := encoder.Create(format) if enc == nil { t.Errorf("No encoder for %q found", format) encoderMissing = true } } if encoderMissing { panic("At least one encoder is missing. See test log") } } func TestMarkdownSpec(t *testing.T) { content, err := ioutil.ReadFile("../testdata/markdown/spec.json") if err != nil { panic(err) } var testcases []markdownTestCase if err = json.Unmarshal(content, &testcases); err != nil { panic(err) } |
︙ | ︙ | |||
105 106 107 108 109 110 111 | } func testAllEncodings(t *testing.T, tc markdownTestCase, ast ast.BlockSlice) { var sb strings.Builder testID := tc.Example*100 + 1 for _, format := range formats { t.Run(fmt.Sprintf("Encode %v %v", format, testID), func(st *testing.T) { | | | | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | } func testAllEncodings(t *testing.T, tc markdownTestCase, ast ast.BlockSlice) { var sb strings.Builder testID := tc.Example*100 + 1 for _, format := range formats { t.Run(fmt.Sprintf("Encode %v %v", format, testID), func(st *testing.T) { encoder.Create(format).WriteBlocks(&sb, ast) sb.Reset() }) } } func testHTMLEncoding(t *testing.T, tc markdownTestCase, ast ast.BlockSlice) { htmlEncoder := encoder.Create("html", &encoder.BoolOption{Key: "xhtml", Value: true}) var sb strings.Builder testID := tc.Example*100 + 1 t.Run(fmt.Sprintf("Encode md html %v", testID), func(st *testing.T) { htmlEncoder.WriteBlocks(&sb, ast) gotHTML := sb.String() sb.Reset() |
︙ | ︙ | |||
137 138 139 140 141 142 143 | st.Errorf("\nCMD: %q\nExp: %q\nGot: %q", tc.Markdown, mdHTML, gotHTML) } } }) } func testZmkEncoding(t *testing.T, tc markdownTestCase, ast ast.BlockSlice) { | | | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | st.Errorf("\nCMD: %q\nExp: %q\nGot: %q", tc.Markdown, mdHTML, gotHTML) } } }) } func testZmkEncoding(t *testing.T, tc markdownTestCase, ast ast.BlockSlice) { zmkEncoder := encoder.Create("zmk") var sb strings.Builder testID := tc.Example*100 + 1 t.Run(fmt.Sprintf("Encode zmk %14d", testID), func(st *testing.T) { zmkEncoder.WriteBlocks(&sb, ast) gotFirst := sb.String() sb.Reset() |
︙ | ︙ |
Changes to tests/regression_test.go.
︙ | ︙ | |||
10 11 12 13 14 15 16 | // Package tests provides some higher-level tests. package tests import ( "context" "fmt" | | < > | | | | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | // Package tests provides some higher-level tests. package tests import ( "context" "fmt" "io/ioutil" "os" "path/filepath" "strings" "testing" "zettelstore.de/z/ast" "zettelstore.de/z/domain" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" "zettelstore.de/z/parser" "zettelstore.de/z/place" _ "zettelstore.de/z/encoder/htmlenc" _ "zettelstore.de/z/encoder/jsonenc" _ "zettelstore.de/z/encoder/nativeenc" _ "zettelstore.de/z/encoder/textenc" _ "zettelstore.de/z/encoder/zmkenc" _ "zettelstore.de/z/parser/blob" _ "zettelstore.de/z/parser/zettelmark" _ "zettelstore.de/z/place/dirplace" "zettelstore.de/z/place/manager" ) var formats = []string{"html", "djson", "native", "text"} func getFilePlaces(wd string, kind string) (root string, places []place.Place) { root = filepath.Clean(filepath.Join(wd, "..", "testdata", kind)) infos, err := ioutil.ReadDir(root) if err != nil { panic(err) } cdata := manager.ConnectData{Filter: &noFilter{}, Notify: nil} for _, info := range infos { if info.Mode().IsDir() { place, err := manager.Connect( "dir://"+filepath.Join(root, info.Name()), false, &cdata, ) if err != nil { panic(err) } places = append(places, place) |
︙ | ︙ | |||
78 79 80 81 82 83 84 | func resultFile(file string) (data string, err error) { f, err := os.Open(file) if err != nil { return "", err } defer f.Close() | | < | | | | < < | | | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | func resultFile(file string) (data string, err error) { f, err := os.Open(file) if err != nil { return "", err } defer f.Close() src, err := ioutil.ReadAll(f) return string(src), err } func checkFileContent(t *testing.T, filename string, gotContent string) { t.Helper() wantContent, err := resultFile(filename) if err != nil { t.Error(err) return } gotContent = trimLastEOL(gotContent) wantContent = trimLastEOL(wantContent) if gotContent != wantContent { t.Errorf("\nWant: %q\nGot: %q", wantContent, gotContent) } } func checkBlocksFile(t *testing.T, resultName string, zn *ast.ZettelNode, format string) { t.Helper() if enc := encoder.Create(format); enc != nil { var sb strings.Builder enc.WriteBlocks(&sb, zn.Ast) checkFileContent(t, resultName, sb.String()) return } panic(fmt.Sprintf("Unknown writer format %q", format)) } func checkZmkEncoder(t *testing.T, zn *ast.ZettelNode) { zmkEncoder := encoder.Create("zmk") var sb strings.Builder zmkEncoder.WriteBlocks(&sb, zn.Ast) gotFirst := sb.String() sb.Reset() newZettel := parser.ParseZettel(domain.Zettel{ Meta: zn.Zettel.Meta, Content: domain.NewContent("\n" + gotFirst)}, "") zmkEncoder.WriteBlocks(&sb, newZettel.Ast) gotSecond := sb.String() sb.Reset() if gotFirst != gotSecond { t.Errorf("\n1st: %q\n2nd: %q", gotFirst, gotSecond) } } func getPlaceName(p place.Place, root string) string { return p.Location()[len("dir://")+len(root):] } func checkContentPlace(t *testing.T, p place.Place, wd, placeName string) { ss := p.(place.StartStopper) if err := ss.Start(context.Background()); err != nil { panic(err) } metaList, err := p.SelectMeta(context.Background(), nil, nil) if err != nil { panic(err) } for _, meta := range metaList { zettel, err := p.GetZettel(context.Background(), meta.Zid) if err != nil { panic(err) |
︙ | ︙ | |||
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | t.Run(fmt.Sprintf("%s::%d", p.Location(), meta.Zid), func(st *testing.T) { checkZmkEncoder(st, z) }) } if err := ss.Stop(context.Background()); err != nil { panic(err) } } func TestContentRegression(t *testing.T) { wd, err := os.Getwd() if err != nil { panic(err) } root, places := getFilePlaces(wd, "content") for _, p := range places { checkContentPlace(t, p, wd, getPlaceName(p, root)) } } func checkMetaFile(t *testing.T, resultName string, zn *ast.ZettelNode, format string) { t.Helper() | > | | | | | 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | t.Run(fmt.Sprintf("%s::%d", p.Location(), meta.Zid), func(st *testing.T) { checkZmkEncoder(st, z) }) } if err := ss.Stop(context.Background()); err != nil { panic(err) } } func TestContentRegression(t *testing.T) { wd, err := os.Getwd() if err != nil { panic(err) } root, places := getFilePlaces(wd, "content") for _, p := range places { checkContentPlace(t, p, wd, getPlaceName(p, root)) } } func checkMetaFile(t *testing.T, resultName string, zn *ast.ZettelNode, format string) { t.Helper() if enc := encoder.Create(format); enc != nil { var sb strings.Builder enc.WriteMeta(&sb, zn.Zettel.Meta) checkFileContent(t, resultName, sb.String()) return } panic(fmt.Sprintf("Unknown writer format %q", format)) } func checkMetaPlace(t *testing.T, p place.Place, wd, placeName string) { ss := p.(place.StartStopper) if err := ss.Start(context.Background()); err != nil { panic(err) } metaList, err := p.SelectMeta(context.Background(), nil, nil) if err != nil { panic(err) } for _, meta := range metaList { zettel, err := p.GetZettel(context.Background(), meta.Zid) if err != nil { panic(err) |
︙ | ︙ |
Changes to tests/result/meta/copyright/20200310125800.djson.
|
| | | 1 | {"title":"Header Test","role":"zettel","syntax":"zmk","copyright":"(c) 2020 Detlef Stern","license":"CC BY-SA 4.0"} |
Changes to tests/result/meta/copyright/20200310125800.native.
|
| | | 1 2 3 4 5 6 | [Title "Header Test"] [Role "zettel"] [Syntax "zmk"] [Header [copyright "(c) 2020 Detlef Stern"], [license "CC BY-SA 4.0"]] |
Changes to tests/result/meta/header/20200310125800.djson.
|
| | | 1 | {"title":"Header Test","role":"zettel","syntax":"zmk","x-no":"00000000000000"} |
Changes to tests/result/meta/header/20200310125800.native.
|
| | | 1 2 3 4 5 | [Title "Header Test"] [Role "zettel"] [Syntax "zmk"] [Header [x-no "00000000000000"]] |
Changes to tests/result/meta/title/20200310110300.djson.
|
| | | 1 | {"title":"A \"\"Title\"\" with //Markup//, ``Zettelmarkup``{=zmk}","role":"zettel","syntax":"zmk"} |
Changes to tests/result/meta/title/20200310110300.html.
|
| | | 1 2 3 | <meta name="zs-title" content="A ""Title"" with //Markup//, ``Zettelmarkup``{=zmk}"> <meta name="zs-role" content="zettel"> <meta name="zs-syntax" content="zmk"> |
Changes to tests/result/meta/title/20200310110300.native.
|
| | | 1 2 3 | [Title "A \"\"Title\"\" with //Markup//, ``Zettelmarkup``{=zmk}"] [Role "zettel"] [Syntax "zmk"] |
Changes to tests/result/meta/title/20200310110300.text.
|
| | | 1 2 3 | A ""Title"" with //Markup//, ``Zettelmarkup``{=zmk} zettel zmk |
Changes to tools/build.go.
︙ | ︙ | |||
14 15 16 17 18 19 20 | import ( "archive/zip" "bytes" "errors" "flag" "fmt" "io" | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import ( "archive/zip" "bytes" "errors" "flag" "fmt" "io" "io/ioutil" "os" "os/exec" "path/filepath" "regexp" "strings" "time" ) |
︙ | ︙ | |||
46 47 48 49 50 51 52 | cmd.Stdout = &out cmd.Stderr = os.Stderr err := cmd.Run() return out.String(), err } func readVersionFile() (string, error) { | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | cmd.Stdout = &out cmd.Stderr = os.Stderr err := cmd.Run() return out.String(), err } func readVersionFile() (string, error) { content, err := ioutil.ReadFile("VERSION") if err != nil { return "", err } return strings.TrimFunc(string(content), func(r rune) bool { return r <= ' ' }), nil } |
︙ | ︙ | |||
130 131 132 133 134 135 136 | } if err := checkGoLint(); err != nil { return err } if err := checkGoVetShadow(); err != nil { return err } | < < < | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | } if err := checkGoLint(); err != nil { return err } if err := checkGoVetShadow(); err != nil { return err } return checkFossilExtra() } func checkGoTest() error { out, err := executeCommand(nil, "go", "test", "./...") if err != nil { for _, line := range splitLines(out) { |
︙ | ︙ | |||
162 163 164 165 166 167 168 | } } return err } func checkGoLint() error { out, err := executeCommand(nil, "golint", "./...") | | > | > < < < < < < < < < < | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | } } return err } func checkGoLint() error { out, err := executeCommand(nil, "golint", "./...") if err != nil { fmt.Fprintln(os.Stderr, "Some lints failed") if len(out) > 0 { fmt.Fprintln(os.Stderr, out) } } return err } func checkGoVetShadow() error { path := findExec("shadow") if path == "" { return nil } out, err := executeCommand(nil, "go", "vet", "-vettool", strings.TrimSpace(path), "./...") if err != nil { fmt.Fprintln(os.Stderr, "Some shadowed variables found") if len(out) > 0 { fmt.Fprintln(os.Stderr, out) } } return err } func checkFossilExtra() error { |
︙ | ︙ | |||
236 237 238 239 240 241 242 | } if len(out) > 0 { fmt.Println(out) } return nil } | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | > > > > > < < < < < | < < < < < < < < < < < < < < | > > | | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | } if len(out) > 0 { fmt.Println(out) } return nil } func cmdRelease() error { base, fossil := getVersionData() if strings.HasSuffix(base, "dev") { base = base[:len(base)-3] + "preview-" + time.Now().Format("20060102") } if strings.HasSuffix(fossil, dirtySuffix) { fmt.Fprintf(os.Stderr, "Warning: releasing a dirty version %v\n", fossil) base = base + dirtySuffix } if err := cmdCheck(); err != nil { return err } releases := []struct { arch string os string env []string name string }{ {"amd64", "linux", nil, "zettelstore"}, {"arm", "linux", []string{"GOARM=6"}, "zettelstore"}, {"amd64", "darwin", nil, "iZettelstore"}, {"arm64", "darwin", nil, "iZettelstore"}, {"amd64", "windows", nil, "zettelstore.exe"}, } for _, rel := range releases { env := append(rel.env, "GOARCH="+rel.arch, "GOOS="+rel.os) zsName := filepath.Join("releases", rel.name) if err := doBuild(env, calcVersion(base, fossil), zsName); err != nil { return err } zipName := fmt.Sprintf("zettelstore-%v-%v-%v.zip", base, rel.os, rel.arch) if err := createZip(zsName, zipName, rel.name); err != nil { return err } if err := os.Remove(zsName); err != nil { return err } } return nil } func createZip(zsName, zipName, fileName string) error { zsFile, err := os.Open(zsName) if err != nil { return err } defer zsFile.Close() zipFile, err := os.OpenFile(filepath.Join("releases", zipName), os.O_RDWR|os.O_CREATE, 0600) if err != nil { return err } defer zipFile.Close() stat, err := zsFile.Stat() if err != nil { return err } fh, err := zip.FileInfoHeader(stat) if err != nil { return err } fh.Name = fileName fh.Method = zip.Deflate zw := zip.NewWriter(zipFile) defer zw.Close() w, err := zw.CreateHeader(fh) if err != nil { return err } _, err = io.Copy(w, zsFile) return err } |
︙ | ︙ | |||
401 402 403 404 405 406 407 | Commands: build Build the software for local computer. check Check current working state: execute tests, static analysis tools, extra files, ... Is automatically done when releasing the software. clean Remove all build and release directories. help Outputs this text. | < | 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | Commands: build Build the software for local computer. check Check current working state: execute tests, static analysis tools, extra files, ... Is automatically done when releasing the software. clean Remove all build and release directories. help Outputs this text. release Create the software for various platforms and put them in appropriate named ZIP files. version Print the current version of the software. All commands can be abbreviated as long as they remain unique.`) } |
︙ | ︙ | |||
424 425 426 427 428 429 430 | args := flag.Args() if len(args) < 1 { cmdHelp() } else { switch args[0] { case "b", "bu", "bui", "buil", "build": err = cmdBuild() | < < | 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | args := flag.Args() if len(args) < 1 { cmdHelp() } else { switch args[0] { case "b", "bu", "bui", "buil", "build": err = cmdBuild() case "r", "re", "rel", "rele", "relea", "releas", "release": err = cmdRelease() case "cl", "cle", "clea", "clean": err = cmdClean() case "v", "ve", "ver", "vers", "versi", "versio", "version": fmt.Print(getVersion()) case "ch", "che", "chec", "check": |
︙ | ︙ |
Changes to usecase/authenticate.go.
︙ | ︙ | |||
16 17 18 19 20 21 22 | "math/rand" "time" "zettelstore.de/z/auth/cred" "zettelstore.de/z/auth/token" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" | | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | "math/rand" "time" "zettelstore.de/z/auth/cred" "zettelstore.de/z/auth/token" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" ) // AuthenticatePort is the interface used by this use case. type AuthenticatePort interface { GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) SelectMeta(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) } // Authenticate is the data for this use case. type Authenticate struct { port AuthenticatePort ucGetUser GetUser } |
︙ | ︙ |
Changes to usecase/context.go.
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | package usecase import ( "context" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" ) // ZettelContextPort is the interface used by this use case. type ZettelContextPort interface { // GetMeta retrieves just the meta data of a specific zettel. GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) } // ZettelContext is the data for this use case. type ZettelContext struct { port ZettelContextPort } | > > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | package usecase import ( "context" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" ) // ZettelContextPort is the interface used by this use case. type ZettelContextPort interface { // GetMeta retrieves just the meta data of a specific zettel. GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) SelectMeta(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) } // ZettelContext is the data for this use case. type ZettelContext struct { port ZettelContextPort } |
︙ | ︙ | |||
105 106 107 108 109 110 111 112 113 114 115 116 117 118 | } } return result, nil } func (uc ZettelContext) addInitialTasks(ctx context.Context, tasks *ztlCtx, start *meta.Meta) { tasks.add(start, 0) } func (uc ZettelContext) addID(ctx context.Context, tasks *ztlCtx, depth int, value string) { if zid, err := id.Parse(value); err == nil { if m, err := uc.port.GetMeta(ctx, zid); err == nil { tasks.add(m, depth) } | > > > > > > > > > > > > > > > > > > | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | } } return result, nil } func (uc ZettelContext) addInitialTasks(ctx context.Context, tasks *ztlCtx, start *meta.Meta) { tasks.add(start, 0) tags, ok := start.GetTags(meta.KeyTags) if !ok { return } filter := place.Filter{Expr: map[string][]string{}} limit := tasks.depth if limit == 0 || limit > 10 { limit = 10 } sorter := place.Sorter{Limit: limit} for _, tag := range tags { filter.Expr[meta.KeyTags] = []string{tag} if ml, err := uc.port.SelectMeta(ctx, &filter, &sorter); err == nil { for _, m := range ml { tasks.add(m, 1) } } } } func (uc ZettelContext) addID(ctx context.Context, tasks *ztlCtx, depth int, value string) { if zid, err := id.Parse(value); err == nil { if m, err := uc.port.GetMeta(ctx, zid); err == nil { tasks.add(m, depth) } |
︙ | ︙ |
Changes to usecase/get_user.go.
︙ | ︙ | |||
14 15 16 17 18 19 20 | import ( "context" "zettelstore.de/z/config/startup" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import ( "context" "zettelstore.de/z/config/startup" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" "zettelstore.de/z/place" ) // Use case: return user identified by meta key ident. // --------------------------------------------------- // GetUserPort is the interface used by this use case. type GetUserPort interface { GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) SelectMeta(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) } // GetUser is the data for this use case. type GetUser struct { port GetUserPort } |
︙ | ︙ | |||
55 56 57 58 59 60 61 | if role, ok := identMeta.Get(meta.KeyRole); !ok || role != meta.ValueRoleUser { return nil, nil } return identMeta, nil } // Owner was not found or has another ident. Try via list search. | | > | | > > | | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | if role, ok := identMeta.Get(meta.KeyRole); !ok || role != meta.ValueRoleUser { return nil, nil } return identMeta, nil } // Owner was not found or has another ident. Try via list search. filter := place.Filter{ Expr: map[string][]string{ meta.KeyRole: {meta.ValueRoleUser}, meta.KeyUserID: {ident}, }, } metaList, err := uc.port.SelectMeta(ctx, &filter, nil) if err != nil { return nil, err } if len(metaList) < 1 { return nil, nil } return metaList[len(metaList)-1], nil |
︙ | ︙ |
Changes to usecase/list_meta.go.
︙ | ︙ | |||
11 12 13 14 15 16 17 | // Package usecase provides (business) use cases for the zettelstore. package usecase import ( "context" "zettelstore.de/z/domain/meta" | | | > | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | // Package usecase provides (business) use cases for the zettelstore. package usecase import ( "context" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" ) // ListMetaPort is the interface used by this use case. type ListMetaPort interface { // SelectMeta returns all zettel meta data that match the selection // criteria. The result is ordered by descending zettel id. SelectMeta(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) } // ListMeta is the data for this use case. type ListMeta struct { port ListMetaPort } // NewListMeta creates a new use case. func NewListMeta(port ListMetaPort) ListMeta { return ListMeta{port: port} } // Run executes the use case. func (uc ListMeta) Run(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) { return uc.port.SelectMeta(ctx, f, s) } |
Changes to usecase/list_role.go.
︙ | ︙ | |||
13 14 15 16 17 18 19 | import ( "context" "sort" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" | | | > | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import ( "context" "sort" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" "zettelstore.de/z/place" ) // ListRolePort is the interface used by this use case. type ListRolePort interface { // SelectMeta returns all zettel meta data that match the selection // criteria. The result is ordered by descending zettel id. SelectMeta(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) } // ListRole is the data for this use case. type ListRole struct { port ListRolePort } // NewListRole creates a new use case. func NewListRole(port ListRolePort) ListRole { return ListRole{port: port} } // Run executes the use case. func (uc ListRole) Run(ctx context.Context) ([]string, error) { metas, err := uc.port.SelectMeta(index.NoEnrichContext(ctx), nil, nil) if err != nil { return nil, err } roles := make(map[string]bool, 8) for _, m := range metas { if role, ok := m.Get(meta.KeyRole); ok && role != "" { roles[role] = true |
︙ | ︙ |
Changes to usecase/list_tags.go.
︙ | ︙ | |||
12 13 14 15 16 17 18 | package usecase import ( "context" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" | | | > | | > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | package usecase import ( "context" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" "zettelstore.de/z/place" ) // ListTagsPort is the interface used by this use case. type ListTagsPort interface { // SelectMeta returns all zettel meta data that match the selection // criteria. The result is ordered by descending zettel id. SelectMeta(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) } // ListTags is the data for this use case. type ListTags struct { port ListTagsPort } // NewListTags creates a new use case. func NewListTags(port ListTagsPort) ListTags { return ListTags{port: port} } // TagData associates tags with a list of all zettel meta that use this tag type TagData map[string][]*meta.Meta // Run executes the use case. func (uc ListTags) Run(ctx context.Context, minCount int) (TagData, error) { metas, err := uc.port.SelectMeta(index.NoEnrichContext(ctx), nil, nil) if err != nil { return nil, err } result := make(TagData) for _, m := range metas { if tl, ok := m.GetList(meta.KeyTags); ok && len(tl) > 0 { for _, t := range tl { t = meta.CleanTag(t) result[t] = append(result[t], m) } } } if minCount > 1 { for t, ms := range result { if len(ms) < minCount { delete(result, t) } } } return result, nil } |
Changes to usecase/order.go.
︙ | ︙ | |||
47 48 49 50 51 52 53 | for _, ref := range collect.Order(zn) { if zid, err := id.Parse(ref.URL.Path); err == nil { if m, err := uc.port.GetMeta(ctx, zid); err == nil { result = append(result, m) } } } | | | 47 48 49 50 51 52 53 54 55 | for _, ref := range collect.Order(zn) { if zid, err := id.Parse(ref.URL.Path); err == nil { if m, err := uc.port.GetMeta(ctx, zid); err == nil { result = append(result, m) } } } return zn.Zettel.Meta, result, nil } |
Changes to usecase/search.go.
︙ | ︙ | |||
12 13 14 15 16 17 18 | package usecase import ( "context" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" | | | > | | > | | > > > > > > > > > > > > > > > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | package usecase import ( "context" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" "zettelstore.de/z/place" ) // SearchPort is the interface used by this use case. type SearchPort interface { // SelectMeta returns all zettel meta data that match the selection // criteria. The result is ordered by descending zettel id. SelectMeta(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) } // Search is the data for this use case. type Search struct { port SearchPort } // NewSearch creates a new use case. func NewSearch(port SearchPort) Search { return Search{port: port} } // Run executes the use case. func (uc Search) Run(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) { // TODO: interpret f.Expr[""]. Can contain expressions for specific meta tags. if !usesComputedMeta(f, s) { ctx = index.NoEnrichContext(ctx) } return uc.port.SelectMeta(ctx, f, s) } func usesComputedMeta(f *place.Filter, s *place.Sorter) bool { if f != nil { for key := range f.Expr { if key == "" || meta.IsComputed(key) { return true } } } if s != nil { if order := s.Order; order != "" && meta.IsComputed(order) { return true } } return false } |
Changes to web/adapter/api/get_links.go.
︙ | ︙ | |||
64 65 66 67 68 69 70 | } outData := jsonGetLinks{ ID: zid.String(), URL: adapter.NewURLBuilder('z').SetZid(zid).String(), } if kind&kindLink != 0 { | > > > > > > > > | > | > > > > > > > > | > > > > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | } outData := jsonGetLinks{ ID: zid.String(), URL: adapter.NewURLBuilder('z').SetZid(zid).String(), } if kind&kindLink != 0 { if matter&matterIncoming != 0 { // Backlinks not yet implemented outData.Links.Incoming = []jsonIDURL{} } zetRefs, locRefs, extRefs := collect.DivideReferences(summary.Links, false) if matter&matterOutgoing != 0 { outData.Links.Outgoing = idURLRefs(zetRefs) } if matter&matterLocal != 0 { outData.Links.Local = stringRefs(locRefs) } if matter&matterExternal != 0 { outData.Links.External = stringRefs(extRefs) } } if kind&kindImage != 0 { zetRefs, locRefs, extRefs := collect.DivideReferences(summary.Images, false) if matter&matterOutgoing != 0 { outData.Images.Outgoing = idURLRefs(zetRefs) } if matter&matterLocal != 0 { outData.Images.Local = stringRefs(locRefs) } if matter&matterExternal != 0 { outData.Images.External = stringRefs(extRefs) } } if kind&kindCite != 0 { outData.Cites = stringCites(summary.Cites) } w.Header().Set(adapter.ContentType, format2ContentType("json")) enc := json.NewEncoder(w) enc.SetEscapeHTML(false) enc.Encode(&outData) } } func idURLRefs(refs []*ast.Reference) []jsonIDURL { result := make([]jsonIDURL, 0, len(refs)) for _, ref := range refs { path := ref.URL.Path ub := adapter.NewURLBuilder('z').AppendPath(path) if fragment := ref.URL.Fragment; len(fragment) > 0 { ub.SetFragment(fragment) |
︙ | ︙ |
Changes to web/adapter/api/get_zettel.go.
︙ | ︙ | |||
61 62 63 64 65 66 67 | } if err != nil { adapter.InternalServerError(w, "Write D/JSON", err) } return } | > | | > | < < < < < < | | > > > > > > > > > | | | | > > > > > > > | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | } if err != nil { adapter.InternalServerError(w, "Write D/JSON", err) } return } langOption := encoder.StringOption{Key: "lang", Value: runtime.GetLang(zn.InhMeta)} linkAdapter := encoder.AdaptLinkOption{ Adapter: adapter.MakeLinkAdapter(ctx, 'z', getMeta, part.DefString(partZettel), format), } imageAdapter := encoder.AdaptImageOption{Adapter: adapter.MakeImageAdapter()} switch part { case partZettel: inhMeta := false if format != "raw" { w.Header().Set(adapter.ContentType, format2ContentType(format)) inhMeta = true } enc := encoder.Create(format, &langOption, &linkAdapter, &imageAdapter, &encoder.StringsOption{ Key: "no-meta", Value: []string{ meta.KeyLang, }, }, ) if enc == nil { err = adapter.ErrNoSuchFormat } else { _, err = enc.WriteZettel(w, zn, inhMeta) } case partMeta: w.Header().Set(adapter.ContentType, format2ContentType(format)) if format == "raw" { // Don't write inherited meta data, just the raw err = writeMeta(w, zn.Zettel.Meta, format) } else { err = writeMeta(w, zn.InhMeta, format) } case partContent: if format == "raw" { if ct, ok := syntax2contentType(runtime.GetSyntax(zn.Zettel.Meta)); ok { w.Header().Add(adapter.ContentType, ct) } } else { w.Header().Set(adapter.ContentType, format2ContentType(format)) } err = writeContent(w, zn, format, &langOption, &encoder.StringOption{ Key: meta.KeyMarkerExternal, Value: runtime.GetMarkerExternal()}, &linkAdapter, &imageAdapter, ) default: adapter.BadRequest(w, "Unknown _part parameter") return } if err != nil { if err == adapter.ErrNoSuchFormat { adapter.BadRequest(w, fmt.Sprintf("Zettel %q not available in format %q", zid.String(), format)) return } adapter.InternalServerError(w, "Get zettel", err) } } } |
Changes to web/adapter/api/get_zettel_list.go.
︙ | ︙ | |||
29 30 31 32 33 34 35 | listMeta usecase.ListMeta, getMeta usecase.GetMeta, parseZettel usecase.ParseZettel, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() q := r.URL.Query() | | | | < > | | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | listMeta usecase.ListMeta, getMeta usecase.GetMeta, parseZettel usecase.ParseZettel, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() q := r.URL.Query() filter, sorter := adapter.GetFilterSorter(q, false) format := adapter.GetFormat(r, q, encoder.GetDefaultFormat()) part := getPart(q, partMeta) ctx1 := ctx if format == "html" || (filter == nil && sorter == nil && (part == partID || part == partContent)) { ctx1 = index.NoEnrichContext(ctx1) } metaList, err := listMeta.Run(ctx1, filter, sorter) if err != nil { adapter.ReportUsecaseError(w, err) return } w.Header().Set(adapter.ContentType, format2ContentType(format)) switch format { case "html": renderListMetaHTML(w, metaList) case "json", "djson": renderListMetaXJSON(ctx, w, metaList, format, part, partMeta, getMeta, parseZettel) case "native", "raw", "text", "zmk": adapter.NotImplemented(w, fmt.Sprintf("Zettel list in format %q not yet implemented", format)) default: adapter.BadRequest(w, fmt.Sprintf("Zettel list not available in format %q", format)) } } } func renderListMetaHTML(w http.ResponseWriter, metaList []*meta.Meta) { buf := encoder.NewBufWriter(w) buf.WriteStrings("<html lang=\"", runtime.GetDefaultLang(), "\">\n<body>\n<ul>\n") for _, m := range metaList { title := m.GetDefault(meta.KeyTitle, "") htmlTitle, err := adapter.FormatInlines(parser.ParseTitle(title), "html") if err != nil { adapter.InternalServerError(w, "Format HTML inlines", err) return } buf.WriteStrings( "<li><a href=\"", adapter.NewURLBuilder('z').SetZid(m.Zid).AppendQuery("format", "html").String(), "\">", htmlTitle, "</a></li>\n") } buf.WriteString("</ul>\n</body>\n</html>") buf.Flush() } |
Changes to web/adapter/api/json.go.
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | "zettelstore.de/z/ast" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" ) type jsonIDURL struct { ID string `json:"id"` URL string `json:"url"` | > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | "zettelstore.de/z/ast" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" "zettelstore.de/z/parser" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" ) type jsonIDURL struct { ID string `json:"id"` URL string `json:"url"` |
︙ | ︙ | |||
61 62 63 64 65 66 67 | idData := jsonIDURL{ ID: z.Zid.String(), URL: adapter.NewURLBuilder('z').SetZid(z.Zid).String(), } switch part { case partZettel: | | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | idData := jsonIDURL{ ID: z.Zid.String(), URL: adapter.NewURLBuilder('z').SetZid(z.Zid).String(), } switch part { case partZettel: encoding, content := encodedContent(z.Zettel.Content) outData = jsonZettel{ ID: idData.ID, URL: idData.URL, Meta: z.InhMeta.Map(), Encoding: encoding, Content: content, } case partMeta: outData = jsonMeta{ ID: idData.ID, URL: idData.URL, Meta: z.InhMeta.Map(), } case partContent: encoding, content := encodedContent(z.Zettel.Content) outData = jsonContent{ ID: idData.ID, URL: idData.URL, Encoding: encoding, Content: content, } case partID: |
︙ | ︙ | |||
171 172 173 174 175 176 177 | } return err } func writeDJSONMeta(w io.Writer, z *ast.ZettelNode) error { _, err := w.Write(djsonMetaHeader) if err == nil { | | | > | > | > | 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | } return err } func writeDJSONMeta(w io.Writer, z *ast.ZettelNode) error { _, err := w.Write(djsonMetaHeader) if err == nil { err = writeMeta(w, z.InhMeta, "djson", &encoder.TitleOption{Inline: z.Title}) } return err } func writeDJSONContent( ctx context.Context, w io.Writer, z *ast.ZettelNode, part, defPart partType, getMeta usecase.GetMeta, ) (err error) { _, err = w.Write(djsonContentHeader) if err == nil { err = writeContent(w, z, "djson", &encoder.AdaptLinkOption{ Adapter: adapter.MakeLinkAdapter(ctx, 'z', getMeta, part.DefString(defPart), "djson"), }, &encoder.AdaptImageOption{Adapter: adapter.MakeImageAdapter()}, ) } return err } var ( jsonListHeader = []byte("{\"list\":[") jsonListSep = []byte{','} |
︙ | ︙ | |||
241 242 243 244 245 246 247 | if err1 != nil { err = err1 break } zn = z } else { zn = &ast.ZettelNode{ | < | > > | | | | | | 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | if err1 != nil { err = err1 break } zn = z } else { zn = &ast.ZettelNode{ Zettel: domain.Zettel{Meta: m, Content: ""}, Zid: m.Zid, InhMeta: runtime.AddDefaultValues(m), Title: parser.ParseTitle( m.GetDefault(meta.KeyTitle, runtime.GetDefaultTitle())), Ast: nil, } } if isJSON { err = writeJSONZettel(w, zn, part) } else { err = writeDJSONZettel(ctx, w, zn, part, defPart, getMeta) } } if err == nil { _, err = w.Write(jsonListFooter) } if err != nil { adapter.InternalServerError(w, "Get list", err) } } func writeContent( w io.Writer, zn *ast.ZettelNode, format string, options ...encoder.Option) error { enc := encoder.Create(format, options...) if enc == nil { return adapter.ErrNoSuchFormat } _, err := enc.WriteContent(w, zn) return err } func writeMeta( w io.Writer, m *meta.Meta, format string, options ...encoder.Option) error { enc := encoder.Create(format, options...) if enc == nil { return adapter.ErrNoSuchFormat } _, err := enc.WriteMeta(w, m) return err } |
︙ | ︙ |
Changes to web/adapter/encoding.go.
︙ | ︙ | |||
25 26 27 28 29 30 31 | "zettelstore.de/z/usecase" ) // ErrNoSuchFormat signals an unsupported encoding format var ErrNoSuchFormat = errors.New("no such format") // FormatInlines returns a string representation of the inline slice. | | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | "zettelstore.de/z/usecase" ) // ErrNoSuchFormat signals an unsupported encoding format var ErrNoSuchFormat = errors.New("no such format") // FormatInlines returns a string representation of the inline slice. func FormatInlines(is ast.InlineSlice, format string, options ...encoder.Option) (string, error) { enc := encoder.Create(format, options...) if enc == nil { return "", ErrNoSuchFormat } var content strings.Builder _, err := enc.WriteInlines(&content, is) if err != nil { |
︙ | ︙ | |||
66 67 68 69 70 71 72 73 74 75 76 77 78 79 | return origLink } zid, err := id.Parse(origRef.URL.Path) if err != nil { panic(err) } _, err = getMeta.Run(index.NoEnrichContext(ctx), zid) if place.IsErrNotAllowed(err) { return &ast.FormatNode{ Code: ast.FormatSpan, Attrs: origLink.Attrs, Inlines: origLink.Inlines, } } | > > > > > > > > > > > > > > > > > < < < < < | | < < < < < < < < < < < < < < < < | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | return origLink } zid, err := id.Parse(origRef.URL.Path) if err != nil { panic(err) } _, err = getMeta.Run(index.NoEnrichContext(ctx), zid) newLink := *origLink if err == nil { u := NewURLBuilder(key).SetZid(zid) if part != "" { u.AppendQuery("_part", part) } if format != "" { u.AppendQuery("_format", format) } if fragment := origRef.URL.EscapedFragment(); len(fragment) > 0 { u.SetFragment(fragment) } newRef := ast.ParseReference(u.String()) newRef.State = ast.RefStateFound newLink.Ref = newRef return &newLink } if place.IsErrNotAllowed(err) { return &ast.FormatNode{ Code: ast.FormatSpan, Attrs: origLink.Attrs, Inlines: origLink.Inlines, } } newRef := ast.ParseReference(origRef.Value) newRef.State = ast.RefStateBroken newLink.Ref = newRef return &newLink } } // MakeImageAdapter creates an adapter to change an image node during encoding. func MakeImageAdapter() func(*ast.ImageNode) ast.InlineNode { return func(origImage *ast.ImageNode) ast.InlineNode { if origImage.Ref == nil || origImage.Ref.State != ast.RefStateZettel { return origImage } newImage := *origImage |
︙ | ︙ |
Changes to web/adapter/request.go.
︙ | ︙ | |||
14 15 16 17 18 19 20 | import ( "net/http" "net/url" "strconv" "strings" "zettelstore.de/z/domain/meta" | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import ( "net/http" "net/url" "strconv" "strings" "zettelstore.de/z/domain/meta" "zettelstore.de/z/place" ) // GetInteger returns the integer value of the named query key. func GetInteger(q url.Values, key string) (int, bool) { s := q.Get(key) if s != "" { if val, err := strconv.Atoi(s); err == nil { |
︙ | ︙ | |||
68 69 70 71 72 73 74 | func contentType2format(contentType string) (string, bool) { // TODO: only check before first ';' format, ok := mapCT2format[contentType] return format, ok } | | | < < < < < < < < < < < < < < < < < < < | | | | | | | | > > | | | | > > > > | | < > | | > | | | > > > | > > > | > > > > | < < < < | | > | | < < | | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | func contentType2format(contentType string) (string, bool) { // TODO: only check before first ';' format, ok := mapCT2format[contentType] return format, ok } // GetFilterSorter retrieves the specified filter and sorting options from a query. func GetFilterSorter(q url.Values, forSearch bool) (filter *place.Filter, sorter *place.Sorter) { sortQKey, orderQKey, offsetQKey, limitQKey, negateQKey, sQKey := getQueryKeys(forSearch) for key, values := range q { switch key { case sortQKey, orderQKey: if len(values) > 0 { descending := false sortkey := values[0] if strings.HasPrefix(sortkey, "-") { descending = true sortkey = sortkey[1:] } if meta.KeyIsValid(sortkey) || sortkey == place.RandomOrder { sorter = place.EnsureSorter(sorter) sorter.Order = sortkey sorter.Descending = descending } } case offsetQKey: if len(values) > 0 { if offset, err := strconv.Atoi(values[0]); err == nil { sorter = place.EnsureSorter(sorter) sorter.Offset = offset } } case limitQKey: if len(values) > 0 { if limit, err := strconv.Atoi(values[0]); err == nil { sorter = place.EnsureSorter(sorter) sorter.Limit = limit } } case negateQKey: filter = place.EnsureFilter(filter) filter.Negate = true case sQKey: if vals := cleanQueryValues(values); len(vals) > 0 { filter = place.EnsureFilter(filter) filter.Expr[""] = vals } default: if !forSearch && meta.KeyIsValid(key) { filter = place.EnsureFilter(filter) filter.Expr[key] = cleanQueryValues(values) } } } return filter, sorter } func getQueryKeys(forSearch bool) (string, string, string, string, string, string) { if forSearch { return "sort", "order", "offset", "limit", "negate", "s" } return "_sort", "_order", "_offset", "_limit", "_negate", "_s" } func cleanQueryValues(values []string) []string { result := make([]string, 0, len(values)) for _, val := range values { val = strings.TrimSpace(val) if len(val) > 0 { result = append(result, val) } } return result } |
Changes to web/adapter/response.go.
︙ | ︙ | |||
9 10 11 12 13 14 15 | //----------------------------------------------------------------------------- // Package adapter provides handlers for web requests. package adapter import ( "fmt" | < < < < < < < < < < < < < < < < < < < < | > | > | | | > | | < < | | > | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | //----------------------------------------------------------------------------- // Package adapter provides handlers for web requests. package adapter import ( "fmt" "net/http" "zettelstore.de/z/place" "zettelstore.de/z/usecase" ) // ReportUsecaseError returns an appropriate HTTP status code for errors in use cases. func ReportUsecaseError(w http.ResponseWriter, err error) { if err == place.ErrNotFound { NotFound(w, http.StatusText(404)) return } if err, ok := err.(*place.ErrNotAllowed); ok { Forbidden(w, err.Error()) return } if err, ok := err.(*place.ErrInvalidID); ok { BadRequest(w, fmt.Sprintf("Zettel-ID %q not appropriate in this context.", err.Zid.String())) return } if err, ok := err.(*usecase.ErrZidInUse); ok { BadRequest(w, fmt.Sprintf("Zettel-ID %q already in use.", err.Zid.String())) return } if err == place.ErrStopped { InternalServerError(w, "Zettelstore not operational.", err) return } InternalServerError(w, "", err) } |
Changes to web/adapter/webui/create_zettel.go.
1 2 3 4 5 6 7 8 9 10 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- | | < < < | < < | > < < | < < | > < < | < < < < | > | > | | | | | < | | | | | | | | | > < | > | < > | | > | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "fmt" "net/http" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" "zettelstore.de/z/index" "zettelstore.de/z/input" "zettelstore.de/z/parser" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/session" ) // MakeGetCopyZettelHandler creates a new HTTP handler to display the // HTML edit view of a copied zettel. func MakeGetCopyZettelHandler( te *TemplateEngine, getZettel usecase.GetZettel, copyZettel usecase.CopyZettel, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if origZettel, ok := getOrigZettel(w, r, getZettel, "Copy"); ok { renderZettelForm(w, r, te, copyZettel.Run(origZettel), "Copy Zettel", "Copy Zettel") } } } // MakeGetFolgeZettelHandler creates a new HTTP handler to display the // HTML edit view of a follow-up zettel. func MakeGetFolgeZettelHandler( te *TemplateEngine, getZettel usecase.GetZettel, folgeZettel usecase.FolgeZettel, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if origZettel, ok := getOrigZettel(w, r, getZettel, "Folge"); ok { renderZettelForm(w, r, te, folgeZettel.Run(origZettel), "Folge Zettel", "Folgezettel") } } } // MakeGetNewZettelHandler creates a new HTTP handler to display the // HTML edit view of a zettel. func MakeGetNewZettelHandler( te *TemplateEngine, getZettel usecase.GetZettel, newZettel usecase.NewZettel, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if origZettel, ok := getOrigZettel(w, r, getZettel, "New"); ok { m := origZettel.Meta title := parser.ParseInlines( input.NewInput(runtime.GetTitle(m)), meta.ValueSyntaxZmk) langOption := encoder.StringOption{Key: "lang", Value: runtime.GetLang(m)} textTitle, err := adapter.FormatInlines(title, "text", &langOption) if err != nil { adapter.InternalServerError(w, "Format Text inlines for WebUI", err) return } htmlTitle, err := adapter.FormatInlines(title, "html", &langOption) if err != nil { adapter.InternalServerError(w, "Format HTML inlines for WebUI", err) return } renderZettelForm(w, r, te, newZettel.Run(origZettel), textTitle, htmlTitle) } } } func getOrigZettel( w http.ResponseWriter, r *http.Request, getZettel usecase.GetZettel, op string, ) (domain.Zettel, bool) { if format := adapter.GetFormat(r, r.URL.Query(), "html"); format != "html" { adapter.BadRequest(w, fmt.Sprintf("%v zettel not possible in format %q", op, format)) return domain.Zettel{}, false } zid, err := id.Parse(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return domain.Zettel{}, false } origZettel, err := getZettel.Run(index.NoEnrichContext(r.Context()), zid) if err != nil { http.NotFound(w, r) return domain.Zettel{}, false } return origZettel, true } func renderZettelForm( w http.ResponseWriter, r *http.Request, te *TemplateEngine, zettel domain.Zettel, |
︙ | ︙ | |||
141 142 143 144 145 146 147 | IsTextContent: !zettel.Content.IsBinary(), Content: zettel.Content.AsString(), }) } // MakePostCreateZettelHandler creates a new HTTP handler to store content of // an existing zettel. | | < | | | < | | > < | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | IsTextContent: !zettel.Content.IsBinary(), Content: zettel.Content.AsString(), }) } // MakePostCreateZettelHandler creates a new HTTP handler to store content of // an existing zettel. func MakePostCreateZettelHandler(createZettel usecase.CreateZettel) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { zettel, hasContent, err := parseZettelForm(r, id.Invalid) if err != nil { adapter.BadRequest(w, "Unable to read form data") return } if !hasContent { adapter.BadRequest(w, "Content is missing") return } if newZid, err := createZettel.Run(r.Context(), zettel); err != nil { adapter.ReportUsecaseError(w, err) } else { http.Redirect(w, r, adapter.NewURLBuilder('h').SetZid(newZid).String(), http.StatusFound) } } } |
Changes to web/adapter/webui/delete_zettel.go.
1 | //----------------------------------------------------------------------------- | | | < < < | | > | | < | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "fmt" "net/http" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/session" ) // MakeGetDeleteZettelHandler creates a new HTTP handler to display the // HTML delete view of a zettel. func MakeGetDeleteZettelHandler( te *TemplateEngine, getZettel usecase.GetZettel, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if format := adapter.GetFormat(r, r.URL.Query(), "html"); format != "html" { adapter.BadRequest(w, fmt.Sprintf("Delete zettel not possible in format %q", format)) return } zid, err := id.Parse(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return } ctx := r.Context() zettel, err := getZettel.Run(ctx, zid) if err != nil { adapter.ReportUsecaseError(w, err) return } user := session.GetUser(ctx) m := zettel.Meta var base baseData te.makeBaseData(ctx, runtime.GetLang(m), "Delete Zettel "+m.Zid.String(), user, &base) te.renderTemplate(ctx, w, id.DeleteTemplateZid, &base, struct { Zid string MetaPairs []meta.Pair }{ Zid: zid.String(), MetaPairs: m.Pairs(true), }) } } // MakePostDeleteZettelHandler creates a new HTTP handler to delete a zettel. func MakePostDeleteZettelHandler(deleteZettel usecase.DeleteZettel) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { zid, err := id.Parse(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return } if err := deleteZettel.Run(r.Context(), zid); err != nil { adapter.ReportUsecaseError(w, err) return } http.Redirect(w, r, adapter.NewURLBuilder('/').String(), http.StatusFound) } } |
Changes to web/adapter/webui/edit_zettel.go.
1 2 3 4 5 6 7 8 9 10 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- | | < < | > | < | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "fmt" "net/http" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/index" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/session" ) // MakeEditGetZettelHandler creates a new HTTP handler to display the // HTML edit view of a zettel. func MakeEditGetZettelHandler( te *TemplateEngine, getZettel usecase.GetZettel) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { zid, err := id.Parse(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return } ctx := r.Context() zettel, err := getZettel.Run(index.NoEnrichContext(ctx), zid) if err != nil { adapter.ReportUsecaseError(w, err) return } if format := adapter.GetFormat(r, r.URL.Query(), "html"); format != "html" { adapter.BadRequest(w, fmt.Sprintf("Edit zettel %q not possible in format %q", zid.String(), format)) return } user := session.GetUser(ctx) m := zettel.Meta var base baseData te.makeBaseData(ctx, runtime.GetLang(m), "Edit Zettel", user, &base) |
︙ | ︙ | |||
64 65 66 67 68 69 70 | Content: zettel.Content.AsString(), }) } } // MakeEditSetZettelHandler creates a new HTTP handler to store content of // an existing zettel. | | < | < | | > | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | Content: zettel.Content.AsString(), }) } } // MakeEditSetZettelHandler creates a new HTTP handler to store content of // an existing zettel. func MakeEditSetZettelHandler(updateZettel usecase.UpdateZettel) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { zid, err := id.Parse(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return } zettel, hasContent, err := parseZettelForm(r, zid) if err != nil { adapter.BadRequest(w, "Unable to read zettel form") return } if err := updateZettel.Run(r.Context(), zettel, hasContent); err != nil { adapter.ReportUsecaseError(w, err) return } http.Redirect( w, r, adapter.NewURLBuilder('h').SetZid(zid).String(), http.StatusFound) } } |
Changes to web/adapter/webui/forms.go.
1 | //----------------------------------------------------------------------------- | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "net/http" "strings" "zettelstore.de/z/domain" |
︙ | ︙ |
Changes to web/adapter/webui/get_info.go.
1 2 3 4 5 6 7 8 9 10 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- | | < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "fmt" "net/http" "strings" "zettelstore.de/z/ast" "zettelstore.de/z/collect" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain/id" "zettelstore.de/z/encoder" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/session" ) type metaDataInfo struct { Key string |
︙ | ︙ | |||
46 47 48 49 50 51 52 | // MakeGetInfoHandler creates a new HTTP handler for the use case "get zettel". func MakeGetInfoHandler( te *TemplateEngine, parseZettel usecase.ParseZettel, getMeta usecase.GetMeta, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { | < < | > > > | > > > > | | < | < > > > | > | | | | | | | | > > > > > > > > > | | | > > | < > > | | | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | // MakeGetInfoHandler creates a new HTTP handler for the use case "get zettel". func MakeGetInfoHandler( te *TemplateEngine, parseZettel usecase.ParseZettel, getMeta usecase.GetMeta, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() if format := adapter.GetFormat(r, q, "html"); format != "html" { adapter.BadRequest(w, fmt.Sprintf("Zettel info not available in format %q", format)) return } zid, err := id.Parse(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return } ctx := r.Context() zn, err := parseZettel.Run(ctx, zid, q.Get("syntax")) if err != nil { adapter.ReportUsecaseError(w, err) return } langOption := &encoder.StringOption{ Key: "lang", Value: runtime.GetLang(zn.InhMeta)} summary := collect.References(zn) locLinks, extLinks := splitLocExtLinks(append(summary.Links, summary.Images...)) textTitle, err := adapter.FormatInlines(zn.Title, "text", nil, langOption) if err != nil { adapter.InternalServerError(w, "Format Text inlines for info", err) return } pairs := zn.Zettel.Meta.Pairs(true) metaData := make([]metaDataInfo, 0, len(pairs)) getTitle := makeGetTitle(ctx, getMeta, langOption) for _, p := range pairs { var html strings.Builder writeHTMLMetaValue(&html, zn.Zettel.Meta, p.Key, getTitle, langOption) metaData = append(metaData, metaDataInfo{p.Key, html.String()}) } formats := encoder.GetFormats() defFormat := encoder.GetDefaultFormat() parts := []string{"zettel", "meta", "content"} matrix := make([]matrixLine, 0, len(parts)) u := adapter.NewURLBuilder('z').SetZid(zid) for _, part := range parts { row := make([]matrixElement, 0, len(formats)+1) row = append(row, matrixElement{part, false, ""}) for _, format := range formats { u.AppendQuery("_part", part) if format != defFormat { u.AppendQuery("_format", format) } row = append(row, matrixElement{format, true, u.String()}) u.ClearQuery() } matrix = append(matrix, matrixLine{row}) } user := session.GetUser(ctx) var base baseData te.makeBaseData(ctx, langOption.Value, textTitle, user, &base) canCopy := base.CanCreate && !zn.Zettel.Content.IsBinary() te.renderTemplate(ctx, w, id.InfoTemplateZid, &base, struct { Zid string WebURL string ContextURL string CanWrite bool EditURL string CanFolge bool |
︙ | ︙ | |||
111 112 113 114 115 116 117 | HasLinks bool HasLocLinks bool LocLinks []string HasExtLinks bool ExtLinks []string ExtNewWindow string Matrix []matrixLine | < | | | | | < | 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | HasLinks bool HasLocLinks bool LocLinks []string HasExtLinks bool ExtLinks []string ExtNewWindow string Matrix []matrixLine }{ Zid: zid.String(), WebURL: adapter.NewURLBuilder('h').SetZid(zid).String(), ContextURL: adapter.NewURLBuilder('j').SetZid(zid).String(), CanWrite: te.canWrite(ctx, user, zn.Zettel), EditURL: adapter.NewURLBuilder('e').SetZid(zid).String(), CanFolge: base.CanCreate && !zn.Zettel.Content.IsBinary(), FolgeURL: adapter.NewURLBuilder('f').SetZid(zid).String(), CanCopy: canCopy, CopyURL: adapter.NewURLBuilder('c').SetZid(zid).String(), CanRename: te.canRename(ctx, user, zn.Zettel.Meta), RenameURL: adapter.NewURLBuilder('b').SetZid(zid).String(), CanDelete: te.canDelete(ctx, user, zn.Zettel.Meta), DeleteURL: adapter.NewURLBuilder('d').SetZid(zid).String(), MetaData: metaData, HasLinks: len(extLinks)+len(locLinks) > 0, HasLocLinks: len(locLinks) > 0, LocLinks: locLinks, HasExtLinks: len(extLinks) > 0, ExtLinks: extLinks, ExtNewWindow: htmlAttrNewWindow(len(extLinks) > 0), Matrix: matrix, }) } } func splitLocExtLinks(links []*ast.Reference) (locLinks, extLinks []string) { if len(links) == 0 { return nil, nil |
︙ | ︙ | |||
157 158 159 160 161 162 163 | extLinks = append(extLinks, ref.String()) } else { locLinks = append(locLinks, ref.String()) } } return locLinks, extLinks } | < < < < < < < < < < < < < < < < < < < < < < | 171 172 173 174 175 176 177 | extLinks = append(extLinks, ref.String()) } else { locLinks = append(locLinks, ref.String()) } } return locLinks, extLinks } |
Changes to web/adapter/webui/get_zettel.go.
1 2 3 4 5 6 7 8 9 10 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- | | < < < | > | > | > | < < | < < < < | | < > | > | < > > > > | > > | > > > > > > > > > > > > | < | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "bytes" "net/http" "strings" "zettelstore.de/z/ast" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/session" ) // MakeGetHTMLZettelHandler creates a new HTTP handler for the use case "get zettel". func MakeGetHTMLZettelHandler( te *TemplateEngine, parseZettel usecase.ParseZettel, getMeta usecase.GetMeta) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { zid, err := id.Parse(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return } ctx := r.Context() syntax := r.URL.Query().Get("syntax") zn, err := parseZettel.Run(ctx, zid, syntax) if err != nil { adapter.ReportUsecaseError(w, err) return } metaHeader, err := formatMeta( zn.InhMeta, "html", &encoder.StringsOption{ Key: "no-meta", Value: []string{meta.KeyTitle, meta.KeyLang}, }, ) if err != nil { adapter.InternalServerError(w, "Format meta", err) return } langOption := encoder.StringOption{Key: "lang", Value: runtime.GetLang(zn.InhMeta)} htmlTitle, err := adapter.FormatInlines(zn.Title, "html", &langOption) if err != nil { adapter.InternalServerError(w, "Format HTML inlines", err) return } textTitle, err := adapter.FormatInlines(zn.Title, "text", &langOption) if err != nil { adapter.InternalServerError(w, "Format text inlines", err) return } newWindow := true htmlContent, err := formatBlocks( zn.Ast, "html", &langOption, &encoder.StringOption{ Key: meta.KeyMarkerExternal, Value: runtime.GetMarkerExternal()}, &encoder.BoolOption{Key: "newwindow", Value: newWindow}, &encoder.AdaptLinkOption{ Adapter: adapter.MakeLinkAdapter(ctx, 'h', getMeta, "", ""), }, &encoder.AdaptImageOption{Adapter: adapter.MakeImageAdapter()}, ) if err != nil { adapter.InternalServerError(w, "Format blocks", err) return } user := session.GetUser(ctx) roleText := zn.Zettel.Meta.GetDefault(meta.KeyRole, "*") tags := buildTagInfos(zn.Zettel.Meta) getTitle := makeGetTitle(ctx, getMeta, &langOption) extURL, hasExtURL := zn.Zettel.Meta.Get(meta.KeyURL) backLinks := formatBackLinks(zn.InhMeta, getTitle) var base baseData te.makeBaseData(ctx, langOption.Value, textTitle, user, &base) base.MetaHeader = metaHeader canCopy := base.CanCreate && !zn.Zettel.Content.IsBinary() te.renderTemplate(ctx, w, id.DetailTemplateZid, &base, struct { HTMLTitle string CanWrite bool EditURL string Zid string InfoURL string RoleText string RoleURL string |
︙ | ︙ | |||
106 107 108 109 110 111 112 | ExtURL string ExtNewWindow string Content string HasBackLinks bool BackLinks []simpleLink }{ HTMLTitle: htmlTitle, | | | | | > | | | | | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | ExtURL string ExtNewWindow string Content string HasBackLinks bool BackLinks []simpleLink }{ HTMLTitle: htmlTitle, CanWrite: te.canWrite(ctx, user, zn.Zettel), EditURL: adapter.NewURLBuilder('e').SetZid(zid).String(), Zid: zid.String(), InfoURL: adapter.NewURLBuilder('i').SetZid(zid).String(), RoleText: roleText, RoleURL: adapter.NewURLBuilder('h').AppendQuery("role", roleText).String(), HasTags: len(tags) > 0, Tags: tags, CanCopy: canCopy, CopyURL: adapter.NewURLBuilder('c').SetZid(zid).String(), CanFolge: base.CanCreate && !zn.Zettel.Content.IsBinary(), FolgeURL: adapter.NewURLBuilder('f').SetZid(zid).String(), FolgeRefs: formatMetaKey(zn.InhMeta, meta.KeyFolge, getTitle), PrecursorRefs: formatMetaKey(zn.InhMeta, meta.KeyPrecursor, getTitle), ExtURL: extURL, HasExtURL: hasExtURL, ExtNewWindow: htmlAttrNewWindow(newWindow && hasExtURL), Content: htmlContent, HasBackLinks: len(backLinks) > 0, BackLinks: backLinks, }) } } func formatBlocks( bs ast.BlockSlice, format string, options ...encoder.Option) (string, error) { enc := encoder.Create(format, options...) if enc == nil { return "", adapter.ErrNoSuchFormat } var content strings.Builder _, err := enc.WriteBlocks(&content, bs) if err != nil { return "", err } return content.String(), nil } func formatMeta(m *meta.Meta, format string, options ...encoder.Option) (string, error) { enc := encoder.Create(format, options...) if enc == nil { return "", adapter.ErrNoSuchFormat } var content strings.Builder _, err := enc.WriteMeta(&content, m) if err != nil { return "", err } return content.String(), nil } func buildTagInfos(m *meta.Meta) []simpleLink { var tagInfos []simpleLink if tags, ok := m.GetList(meta.KeyTags); ok { ub := adapter.NewURLBuilder('h') tagInfos = make([]simpleLink, len(tags)) for i, tag := range tags { tagInfos[i] = simpleLink{Text: tag, URL: ub.AppendQuery("tags", meta.CleanTag(tag)).String()} ub.ClearQuery() } } return tagInfos } func formatMetaKey(m *meta.Meta, key string, getTitle getTitleFunc) string { |
︙ | ︙ |
Changes to web/adapter/webui/home.go.
1 2 3 4 5 6 7 8 9 10 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "context" "net/http" "zettelstore.de/z/config/runtime" |
︙ | ︙ | |||
26 27 28 29 30 31 32 | type getRootStore interface { // GetMeta retrieves just the meta data of a specific zettel. GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) } // MakeGetRootHandler creates a new HTTP handler to show the root URL. | | < | > > | | | | > < > | | | | | < | | | > | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | type getRootStore interface { // GetMeta retrieves just the meta data of a specific zettel. GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) } // MakeGetRootHandler creates a new HTTP handler to show the root URL. func MakeGetRootHandler(s getRootStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { http.NotFound(w, r) return } ok := false ctx := r.Context() homeZid := runtime.GetHomeZettel() if homeZid != id.DefaultHomeZid && homeZid.IsValid() { if _, err := s.GetMeta(ctx, homeZid); err != nil { homeZid = id.DefaultHomeZid } else { ok = true } } if !ok { if _, err := s.GetMeta(ctx, homeZid); err != nil { if place.IsErrNotAllowed(err) && startup.WithAuth() && session.GetUser(ctx) == nil { http.Redirect(w, r, adapter.NewURLBuilder('a').String(), http.StatusFound) return } http.Redirect(w, r, adapter.NewURLBuilder('h').String(), http.StatusFound) return } } http.Redirect(w, r, adapter.NewURLBuilder('h').SetZid(homeZid).String(), http.StatusFound) } } |
Changes to web/adapter/webui/htmlmeta.go.
1 2 3 4 5 6 7 8 9 10 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "context" "fmt" "io" "net/url" |
︙ | ︙ | |||
27 28 29 30 31 32 33 | "zettelstore.de/z/strfun" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" ) var space = []byte{' '} | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | "zettelstore.de/z/strfun" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" ) var space = []byte{' '} func writeHTMLMetaValue(w io.Writer, m *meta.Meta, key string, getTitle getTitleFunc, option encoder.Option) { switch kt := m.Type(key); kt { case meta.TypeBool: writeHTMLBool(w, key, m.GetBool(key)) case meta.TypeCredential: writeCredential(w, m.GetDefault(key, "???c")) case meta.TypeEmpty: writeEmpty(w, m.GetDefault(key, "???e")) |
︙ | ︙ | |||
62 63 64 65 66 67 68 | case meta.TypeWord: writeWord(w, key, m.GetDefault(key, "???w")) case meta.TypeWordSet: if l, ok := m.GetList(key); ok { writeWordSet(w, key, l) } case meta.TypeZettelmarkup: | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | case meta.TypeWord: writeWord(w, key, m.GetDefault(key, "???w")) case meta.TypeWordSet: if l, ok := m.GetList(key); ok { writeWordSet(w, key, l) } case meta.TypeZettelmarkup: writeZettelmarkup(w, m.GetDefault(key, "???z"), option) case meta.TypeUnknown: writeUnknown(w, m.GetDefault(key, "???u")) default: strfun.HTMLEscape(w, m.GetDefault(key, "???w"), false) fmt.Fprintf(w, " <b>(Unhandled type: %v, key: %v)</b>", kt, key) } } |
︙ | ︙ | |||
140 141 142 143 144 145 146 | } func writeTagSet(w io.Writer, key string, tags []string) { for i, tag := range tags { if i > 0 { w.Write(space) } | | | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | } func writeTagSet(w io.Writer, key string, tags []string) { for i, tag := range tags { if i > 0 { w.Write(space) } writeLink(w, key, meta.CleanTag(tag), tag) } } func writeTimestamp(w io.Writer, ts time.Time) { io.WriteString(w, ts.Format("2006-01-02 15:04:05")) } |
︙ | ︙ | |||
171 172 173 174 175 176 177 | for i, word := range words { if i > 0 { w.Write(space) } writeWord(w, key, word) } } | | > | | | | | 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | for i, word := range words { if i > 0 { w.Write(space) } writeWord(w, key, word) } } func writeZettelmarkup(w io.Writer, val string, option encoder.Option) { astTitle := parser.ParseTitle(val) title, err := adapter.FormatInlines(astTitle, "html", option) if err != nil { strfun.HTMLEscape(w, val, false) return } io.WriteString(w, title) } func writeLink(w io.Writer, key, value, text string) { fmt.Fprintf( w, "<a href=\"%v?%v=%v\">", adapter.NewURLBuilder('h'), url.QueryEscape(key), url.QueryEscape(value)) strfun.HTMLEscape(w, text, false) io.WriteString(w, "</a>") } type getTitleFunc func(id.Zid, string) (string, int) func makeGetTitle(ctx context.Context, getMeta usecase.GetMeta, langOption encoder.Option) getTitleFunc { return func(zid id.Zid, format string) (string, int) { m, err := getMeta.Run(index.NoEnrichContext(ctx), zid) if err != nil { if place.IsErrNotAllowed(err) { return "", -1 } return "", 0 } astTitle := parser.ParseTitle(m.GetDefault(meta.KeyTitle, "")) title, err := adapter.FormatInlines(astTitle, format, langOption) if err == nil { return title, 1 } return "", 1 } } |
Changes to web/adapter/webui/lists.go.
1 2 3 4 5 6 7 8 9 10 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- | | < | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "context" "net/http" "net/url" "sort" "strconv" "strings" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" "zettelstore.de/z/index" "zettelstore.de/z/parser" "zettelstore.de/z/place" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/session" ) // MakeListHTMLMetaHandler creates a HTTP handler for rendering the list of zettel as HTML. func MakeListHTMLMetaHandler( te *TemplateEngine, listMeta usecase.ListMeta, listRole usecase.ListRole, listTags usecase.ListTags, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { |
︙ | ︙ | |||
52 53 54 55 56 57 58 | } } } func renderWebUIZettelList( w http.ResponseWriter, r *http.Request, te *TemplateEngine, listMeta usecase.ListMeta) { query := r.URL.Query() | | | | | > | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | } } } func renderWebUIZettelList( w http.ResponseWriter, r *http.Request, te *TemplateEngine, listMeta usecase.ListMeta) { query := r.URL.Query() filter, sorter := adapter.GetFilterSorter(query, false) ctx := r.Context() title := listTitleFilterSorter("Filter", filter, sorter) renderWebUIMetaList( ctx, w, te, title, sorter, func(sorter *place.Sorter) ([]*meta.Meta, error) { if filter == nil && (sorter == nil || sorter.Order == "") { ctx = index.NoEnrichContext(ctx) } return listMeta.Run(ctx, filter, sorter) }, func(offset int) string { return newPageURL('h', query, offset, "_offset", "_limit") }) } type roleInfo struct { |
︙ | ︙ | |||
127 128 129 130 131 132 133 | te *TemplateEngine, listTags usecase.ListTags, ) { ctx := r.Context() iMinCount, _ := strconv.Atoi(r.URL.Query().Get("min")) tagData, err := listTags.Run(ctx, iMinCount) if err != nil { | | | 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | te *TemplateEngine, listTags usecase.ListTags, ) { ctx := r.Context() iMinCount, _ := strconv.Atoi(r.URL.Query().Get("min")) tagData, err := listTags.Run(ctx, iMinCount) if err != nil { adapter.ReportUsecaseError(w, err) return } user := session.GetUser(ctx) tagsList := make([]tagInfo, 0, len(tagData)) countMap := make(map[int]int) baseTagListURL := adapter.NewURLBuilder('h') |
︙ | ︙ | |||
164 165 166 167 168 169 170 | } var base baseData te.makeBaseData(ctx, runtime.GetDefaultLang(), runtime.GetSiteName(), user, &base) minCounts := make([]countInfo, 0, len(countList)) for _, c := range countList { sCount := strconv.Itoa(c) | | < | | < | | | | | | | | | > | < | > > | > > > | > > | | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | } var base baseData te.makeBaseData(ctx, runtime.GetDefaultLang(), runtime.GetSiteName(), user, &base) minCounts := make([]countInfo, 0, len(countList)) for _, c := range countList { sCount := strconv.Itoa(c) minCounts = append(minCounts, countInfo{sCount, base.ListTagsURL + "?min=" + sCount}) } te.renderTemplate(ctx, w, id.TagsTemplateZid, &base, struct { MinCounts []countInfo Tags []tagInfo }{ MinCounts: minCounts, Tags: tagsList, }) } // MakeSearchHandler creates a new HTTP handler for the use case "search". func MakeSearchHandler( te *TemplateEngine, search usecase.Search, getMeta usecase.GetMeta, getZettel usecase.GetZettel, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() filter, sorter := adapter.GetFilterSorter(query, true) if filter == nil || len(filter.Expr) == 0 { http.Redirect(w, r, adapter.NewURLBuilder('h').String(), http.StatusFound) return } ctx := r.Context() title := listTitleFilterSorter("Search", filter, sorter) renderWebUIMetaList( ctx, w, te, title, sorter, func(sorter *place.Sorter) ([]*meta.Meta, error) { if filter == nil && (sorter == nil || sorter.Order == "") { ctx = index.NoEnrichContext(ctx) } return search.Run(ctx, filter, sorter) }, func(offset int) string { return newPageURL('f', query, offset, "offset", "limit") }) } } // MakeZettelContextHandler creates a new HTTP handler for the use case "zettel context". func MakeZettelContextHandler(te *TemplateEngine, getContext usecase.ZettelContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { zid, err := id.Parse(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return } q := r.URL.Query() dir := usecase.ParseZCDirection(q.Get("dir")) depth, ok := adapter.GetInteger(q, "depth") if !ok || depth < 0 { depth = 5 } limit, ok := adapter.GetInteger(q, "limit") if !ok || limit < 0 { limit = 200 } ctx := r.Context() metaList, err := getContext.Run(ctx, zid, dir, depth, limit) if err != nil { adapter.ReportUsecaseError(w, err) return } metaLinks, err := buildHTMLMetaList(metaList) if err != nil { adapter.InternalServerError(w, "Build HTML meta list", err) return } |
︙ | ︙ | |||
266 267 268 269 270 271 272 | Depths: depthLinks, Start: metaLinks[0], Metas: metaLinks[1:], }) } } | < < < < < < < < | | > | | | | | | | | | | | 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | Depths: depthLinks, Start: metaLinks[0], Metas: metaLinks[1:], }) } } func renderWebUIMetaList( ctx context.Context, w http.ResponseWriter, te *TemplateEngine, title string, sorter *place.Sorter, ucMetaList func(sorter *place.Sorter) ([]*meta.Meta, error), pageURL func(int) string) { var metaList []*meta.Meta var err error var prevURL, nextURL string if lps := runtime.GetListPageSize(); lps > 0 { sorter = place.EnsureSorter(sorter) if sorter.Limit < lps { sorter.Limit = lps + 1 } metaList, err = ucMetaList(sorter) if err != nil { adapter.ReportUsecaseError(w, err) return } if offset := sorter.Offset; offset > 0 { offset -= lps if offset < 0 { offset = 0 } prevURL = pageURL(offset) } if len(metaList) >= sorter.Limit { nextURL = pageURL(sorter.Offset + lps) metaList = metaList[:len(metaList)-1] } } else { metaList, err = ucMetaList(sorter) if err != nil { adapter.ReportUsecaseError(w, err) return } } user := session.GetUser(ctx) metas, err := buildHTMLMetaList(metaList) if err != nil { adapter.InternalServerError(w, "Build HTML meta list", err) return } var base baseData te.makeBaseData(ctx, runtime.GetDefaultLang(), runtime.GetSiteName(), user, &base) te.renderTemplate(ctx, w, id.ListTemplateZid, &base, struct { Title string Metas []simpleLink |
︙ | ︙ | |||
339 340 341 342 343 344 345 | HasPrev: len(prevURL) > 0, PrevURL: prevURL, HasNext: len(nextURL) > 0, NextURL: nextURL, }) } | | | > | > > | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < | | | < | > | 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | HasPrev: len(prevURL) > 0, PrevURL: prevURL, HasNext: len(nextURL) > 0, NextURL: nextURL, }) } func listTitleFilterSorter(prefix string, filter *place.Filter, sorter *place.Sorter) string { if filter == nil && sorter == nil { return runtime.GetSiteName() } var sb strings.Builder sb.WriteString(prefix) sb.WriteString(": ") if filter != nil { listTitleFilter(&sb, filter) if sorter != nil { sb.WriteString(" | ") listTitleSorter(&sb, sorter) } } else if sorter != nil { listTitleSorter(&sb, sorter) } return sb.String() } func listTitleFilter(sb *strings.Builder, filter *place.Filter) { if filter.Negate { sb.WriteString("NOT (") } names := make([]string, 0, len(filter.Expr)) for name := range filter.Expr { names = append(names, name) } sort.Strings(names) for i, name := range names { if i > 0 { sb.WriteString(" AND ") } if name == "" { sb.WriteString("ANY") } else { sb.WriteString(name) } sb.WriteString(" MATCH ") writeFilterExprValues(sb, filter.Expr[name]) } if filter.Negate { sb.WriteByte(')') } } func writeFilterExprValues(sb *strings.Builder, values []string) { if len(values) == 0 { sb.WriteString("ANY") return } for j, val := range values { if j > 0 { sb.WriteString(" AND ") } if val == "" { sb.WriteString("ANY") } else { sb.WriteString(val) } } } func listTitleSorter(sb *strings.Builder, sorter *place.Sorter) { var space bool if ord := sorter.Order; len(ord) > 0 { switch ord { case meta.KeyID: // Ignore case place.RandomOrder: sb.WriteString("RANDOM") space = true default: sb.WriteString("SORT ") sb.WriteString(ord) if sorter.Descending { sb.WriteString(" DESC") } space = true } } if off := sorter.Offset; off > 0 { if space { sb.WriteByte(' ') } sb.WriteString("OFFSET ") sb.WriteString(strconv.Itoa(off)) space = true } if lim := sorter.Limit; lim > 0 { if space { sb.WriteByte(' ') } sb.WriteString("LIMIT ") sb.WriteString(strconv.Itoa(lim)) } } func newPageURL(key byte, query url.Values, offset int, offsetKey, limitKey string) string { urlBuilder := adapter.NewURLBuilder(key) for key, values := range query { if key != offsetKey && key != limitKey { for _, val := range values { urlBuilder.AppendQuery(key, val) } } } if offset > 0 { urlBuilder.AppendQuery(offsetKey, strconv.Itoa(offset)) } return urlBuilder.String() } // buildHTMLMetaList builds a zettel list based on a meta list for HTML rendering. func buildHTMLMetaList(metaList []*meta.Meta) ([]simpleLink, error) { defaultLang := runtime.GetDefaultLang() langOption := encoder.StringOption{Key: "lang", Value: ""} metas := make([]simpleLink, 0, len(metaList)) for _, m := range metaList { if lang, ok := m.Get(meta.KeyLang); ok { langOption.Value = lang } else { langOption.Value = defaultLang } title, _ := m.Get(meta.KeyTitle) htmlTitle, err := adapter.FormatInlines( parser.ParseTitle(title), "html", &langOption) if err != nil { return nil, err } metas = append(metas, simpleLink{ Text: htmlTitle, URL: adapter.NewURLBuilder('h').SetZid(m.Zid).String(), }) } return metas, nil } |
Changes to web/adapter/webui/login.go.
1 | //----------------------------------------------------------------------------- | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //----------------------------------------------------------------------------- // Copyright (c) 2020 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "context" "fmt" "net/http" "time" |
︙ | ︙ | |||
45 46 47 48 49 50 51 | }) } // MakePostLoginHandlerHTML creates a new HTTP handler to authenticate the given user. func MakePostLoginHandlerHTML(te *TemplateEngine, auth usecase.Authenticate) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if !startup.WithAuth() { | | < | > | | | < | | | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | }) } // MakePostLoginHandlerHTML creates a new HTTP handler to authenticate the given user. func MakePostLoginHandlerHTML(te *TemplateEngine, auth usecase.Authenticate) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if !startup.WithAuth() { http.Redirect(w, r, adapter.NewURLBuilder('/').String(), http.StatusFound) return } htmlDur, _ := startup.TokenLifetime() authenticateViaHTML(te, auth, w, r, htmlDur) } } func authenticateViaHTML( te *TemplateEngine, auth usecase.Authenticate, w http.ResponseWriter, r *http.Request, authDuration time.Duration, ) { ident, cred, ok := adapter.GetCredentialsViaForm(r) if !ok { adapter.BadRequest(w, "Unable to read login form") return } ctx := r.Context() token, err := auth.Run(ctx, ident, cred, authDuration, token.KindHTML) if err != nil { adapter.ReportUsecaseError(w, err) return } if token == nil { renderLoginForm(session.ClearToken(ctx, w), w, te, true) return } session.SetToken(w, token, authDuration) http.Redirect(w, r, adapter.NewURLBuilder('/').String(), http.StatusFound) } // MakeGetLogoutHandler creates a new HTTP handler to log out the current user func MakeGetLogoutHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if format := adapter.GetFormat(r, r.URL.Query(), "html"); format != "html" { adapter.BadRequest(w, fmt.Sprintf("Logout not possible in format %q", format)) return } session.ClearToken(r.Context(), w) http.Redirect(w, r, adapter.NewURLBuilder('/').String(), http.StatusFound) } } |
Changes to web/adapter/webui/rename_zettel.go.
1 2 3 4 5 6 7 8 9 10 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- | | < < | > | < | | < | < | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "fmt" "net/http" "strings" "zettelstore.de/z/config/runtime" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/session" ) // MakeGetRenameZettelHandler creates a new HTTP handler to display the // HTML rename view of a zettel. func MakeGetRenameZettelHandler( te *TemplateEngine, getMeta usecase.GetMeta) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { zid, err := id.Parse(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return } ctx := r.Context() m, err := getMeta.Run(ctx, zid) if err != nil { adapter.ReportUsecaseError(w, err) return } if format := adapter.GetFormat(r, r.URL.Query(), "html"); format != "html" { adapter.BadRequest(w, fmt.Sprintf("Rename zettel %q not possible in format %q", zid.String(), format)) return } user := session.GetUser(ctx) var base baseData te.makeBaseData(ctx, runtime.GetLang(m), "Rename Zettel "+zid.String(), user, &base) te.renderTemplate(ctx, w, id.RenameTemplateZid, &base, struct { Zid string MetaPairs []meta.Pair }{ Zid: zid.String(), MetaPairs: m.Pairs(true), }) } } // MakePostRenameZettelHandler creates a new HTTP handler to rename an existing zettel. func MakePostRenameZettelHandler(renameZettel usecase.RenameZettel) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { curZid, err := id.Parse(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return } if err = r.ParseForm(); err != nil { adapter.BadRequest(w, "Unable to read rename zettel form") return } if formCurZid, err1 := id.Parse( r.PostFormValue("curzid")); err1 != nil || formCurZid != curZid { adapter.BadRequest(w, "Invalid value for current zettel id in form") return } newZid, err := id.Parse(strings.TrimSpace(r.PostFormValue("newzid"))) if err != nil { adapter.BadRequest(w, fmt.Sprintf("Invalid new zettel id %q", newZid.String())) return } if err := renameZettel.Run(r.Context(), curZid, newZid); err != nil { adapter.ReportUsecaseError(w, err) return } http.Redirect(w, r, adapter.NewURLBuilder('h').SetZid(newZid).String(), http.StatusFound) } } |
Deleted web/adapter/webui/response.go.
|
| < < < < < < < < < < < < < < < < < < < < < < |
Changes to web/adapter/webui/template.go.
1 2 3 4 5 6 7 8 9 10 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- | | < < > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | //----------------------------------------------------------------------------- // Copyright (c) 2020-2021 Detlef Stern // // This file is part of zettelstore. // // Zettelstore is licensed under the latest version of the EUPL (European Union // Public License). Please see file LICENSE.txt for your rights and obligations // under this license. //----------------------------------------------------------------------------- // Package webui provides wet-UI handlers for web requests. package webui import ( "bytes" "context" "net/http" "sync" "zettelstore.de/z/auth/policy" "zettelstore.de/z/auth/token" "zettelstore.de/z/collect" "zettelstore.de/z/config/runtime" "zettelstore.de/z/config/startup" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" "zettelstore.de/z/index" "zettelstore.de/z/input" "zettelstore.de/z/parser" "zettelstore.de/z/place" "zettelstore.de/z/template" "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/session" ) type templatePlace interface { CanCreateZettel(ctx context.Context) bool GetZettel(ctx context.Context, zid id.Zid) (domain.Zettel, error) GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error) SelectMeta(ctx context.Context, f *place.Filter, s *place.Sorter) ([]*meta.Meta, error) CanUpdateZettel(ctx context.Context, zettel domain.Zettel) bool AllowRenameZettel(ctx context.Context, zid id.Zid) bool CanDeleteZettel(ctx context.Context, zid id.Zid) bool } // TemplateEngine is the way to render HTML templates. type TemplateEngine struct { |
︙ | ︙ | |||
76 77 78 79 80 81 82 | listZettelURL: adapter.NewURLBuilder('h').String(), listRolesURL: adapter.NewURLBuilder('h').AppendQuery("_l", "r").String(), listTagsURL: adapter.NewURLBuilder('h').AppendQuery("_l", "t").String(), withAuth: startup.WithAuth(), loginURL: adapter.NewURLBuilder('a').String(), searchURL: adapter.NewURLBuilder('f').String(), } | | | | | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | listZettelURL: adapter.NewURLBuilder('h').String(), listRolesURL: adapter.NewURLBuilder('h').AppendQuery("_l", "r").String(), listTagsURL: adapter.NewURLBuilder('h').AppendQuery("_l", "t").String(), withAuth: startup.WithAuth(), loginURL: adapter.NewURLBuilder('a').String(), searchURL: adapter.NewURLBuilder('f').String(), } te.observe(place.ChangeInfo{Reason: place.OnReload, Zid: id.Invalid}) mgr.RegisterObserver(te.observe) return te } func (te *TemplateEngine) observe(ci place.ChangeInfo) { te.mxCache.Lock() if ci.Reason == place.OnReload || ci.Zid == id.BaseTemplateZid { te.templateCache = make(map[id.Zid]*template.Template, len(te.templateCache)) } else { delete(te.templateCache, ci.Zid) } te.mxCache.Unlock() } |
︙ | ︙ | |||
110 111 112 113 114 115 116 | func (te *TemplateEngine) canCreate(ctx context.Context, user *meta.Meta) bool { m := meta.New(id.Invalid) return te.policy.CanCreate(user, m) && te.place.CanCreateZettel(ctx) } func (te *TemplateEngine) canWrite( | | | | | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | func (te *TemplateEngine) canCreate(ctx context.Context, user *meta.Meta) bool { m := meta.New(id.Invalid) return te.policy.CanCreate(user, m) && te.place.CanCreateZettel(ctx) } func (te *TemplateEngine) canWrite( ctx context.Context, user *meta.Meta, zettel domain.Zettel) bool { return te.policy.CanWrite(user, zettel.Meta, zettel.Meta) && te.place.CanUpdateZettel(ctx, zettel) } func (te *TemplateEngine) canRename(ctx context.Context, user, m *meta.Meta) bool { return te.policy.CanRename(user, m) && te.place.AllowRenameZettel(ctx, m.Zid) } func (te *TemplateEngine) canDelete(ctx context.Context, user, m *meta.Meta) bool { |
︙ | ︙ | |||
239 240 241 242 243 244 245 | if err != nil { continue } if !te.policy.CanRead(user, m) { continue } title := runtime.GetTitle(m) | > | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | if err != nil { continue } if !te.policy.CanRead(user, m) { continue } title := runtime.GetTitle(m) langOption := encoder.StringOption{Key: "lang", Value: runtime.GetLang(m)} astTitle := parser.ParseInlines( input.NewInput(runtime.GetTitle(m)), meta.ValueSyntaxZmk) menuTitle, err := adapter.FormatInlines(astTitle, "html", &langOption) if err != nil { menuTitle, err = adapter.FormatInlines(astTitle, "text", &langOption) if err != nil { menuTitle = title } } result = append(result, simpleLink{ Text: menuTitle, URL: adapter.NewURLBuilder('g').SetZid(m.Zid).String(), }) } return result } func (te *TemplateEngine) renderTemplate( ctx context.Context, w http.ResponseWriter, templateID id.Zid, base *baseData, data interface{}) { bt, err := te.getTemplate(ctx, id.BaseTemplateZid) if err != nil { adapter.InternalServerError(w, "Unable to get base template", err) |
︙ | ︙ | |||
311 312 313 314 315 316 317 | } } var content bytes.Buffer err = t.Render(&content, data) if err == nil { base.Content = content.String() w.Header().Set(adapter.ContentType, "text/html; charset=utf-8") | < | | 284 285 286 287 288 289 290 291 292 293 294 295 296 | } } var content bytes.Buffer err = t.Render(&content, data) if err == nil { base.Content = content.String() w.Header().Set(adapter.ContentType, "text/html; charset=utf-8") err = bt.Render(w, base) } if err != nil { adapter.InternalServerError(w, "Unable to render template", err) } } |
Changes to www/changes.wiki.
1 2 | <title>Change Log</title> | < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1 2 3 4 5 6 7 8 9 10 11 | <title>Change Log</title> <a name="0_0_11"></a> <h2>Changes for Version 0.0.11 (pending)</h2> <a name="0_0_10"></a> <h2>Changes for Version 0.0.10 (2021-02-26)</h2> * Menu item “Home” now redirects to a home zettel. Its default identifier is <tt>000100000000</tt>. The identifier can be changed with configuration key <tt>home-zettel</tt>, which supersedes key <tt>start</tt>. The default home zettel contains some welcoming information for the new user. |
︙ | ︙ | |||
134 135 136 137 138 139 140 | * (major) HTML template zettel for WebUI now use [https://mustache.github.io/|Mustache] syntax instead of previously used [https://golang.org/pkg/html/template/|Go template] syntax. This allows these zettel to be used, even when there is another Zettelstore implementation, in another programming language. Mustache is available for approx. 48 programming languages, instead of only one for Go templates. <b>If you modified your templates, you <i>must</i> adapt them to the new syntax. Otherwise the WebUI will not work.</b> * (major) Show zettel identifier of folgezettel and precursor zettel in the header of a rendered zettel. | | | | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | * (major) HTML template zettel for WebUI now use [https://mustache.github.io/|Mustache] syntax instead of previously used [https://golang.org/pkg/html/template/|Go template] syntax. This allows these zettel to be used, even when there is another Zettelstore implementation, in another programming language. Mustache is available for approx. 48 programming languages, instead of only one for Go templates. <b>If you modified your templates, you <i>must</i> adapt them to the new syntax. Otherwise the WebUI will not work.</b> * (major) Show zettel identifier of folgezettel and precursor zettel in the header of a rendered zettel. If a zettel has backlinks, they are shown at the botton of the page (“Links to this zettel”). * (minor) All property metadata, even computed metadata is shown in the info page of a zettel. * (minor) Rendering of metadata keys <tt>title</tt> and <tt>default-title</tt> in info page changed to a full HTML output for these Zettelmarkup encoded values. * (minor) Always show the zettel identifier on the zettel detail view. Previously, the identifier was not shown if the zettel was not editable. * (minor) Do not show computed metadata in edit forms anymore. <a name="0_0_8"></a> |
︙ | ︙ |
Changes to www/download.wiki.
1 2 3 4 5 6 7 8 9 10 11 | <title>Download</title> <h1>Download of Zettelstore Software</h1> <h2>Foreword</h2> * Zettelstore is free/libre open source software, licensed under EUPL-1.2-or-later. * The software is provided as-is. * There is no guarantee that it will not damage your system. * However, it is in use by the main developer since March 2020 without any damage. * It may be useful for you. It is useful for me. * Take a look at the [https://zettelstore.de/manual/|manual] to know how to start and use it. <h2>ZIP-ped Executables</h2> | | | | | | | | | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <title>Download</title> <h1>Download of Zettelstore Software</h1> <h2>Foreword</h2> * Zettelstore is free/libre open source software, licensed under EUPL-1.2-or-later. * The software is provided as-is. * There is no guarantee that it will not damage your system. * However, it is in use by the main developer since March 2020 without any damage. * It may be useful for you. It is useful for me. * Take a look at the [https://zettelstore.de/manual/|manual] to know how to start and use it. <h2>ZIP-ped Executables</h2> Build: <code>v0.0.10</code> (2021-02-26). * [/uv/zettelstore-0.0.10-linux-amd64.zip|Linux] (amd64) * [/uv/zettelstore-0.0.10-linux-arm.zip|Linux] (arm6, e.g. Raspberry Pi) * [/uv/zettelstore-0.0.10-windows-amd64.zip|Windows] (amd64) * [/uv/zettelstore-0.0.10-darwin-amd64.zip|macOS] (amd64) * [/uv/zettelstore-0.0.10-darwin-arm64.zip|macOS] (arm64, aka Apple silicon) Unzip the appropriate file, install and execute Zettelstore according to the manual. <h2>Zettel for the manual</h2> As a starter, you can download the zettel for the manual [/uv/manual-0.0.10.zip|here]. Just unzip the contained files and put them into your zettel folder. |
Changes to www/index.wiki.
︙ | ︙ | |||
13 14 15 16 17 18 19 | It is a live example of the zettelstore software, running in read-only mode. The software, including the manual, is licensed under the [/file?name=LICENSE.txt&ci=trunk|European Union Public License 1.2 (or later)]. [https://twitter.com/zettelstore|Stay tuned]… <hr> | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | It is a live example of the zettelstore software, running in read-only mode. The software, including the manual, is licensed under the [/file?name=LICENSE.txt&ci=trunk|European Union Public License 1.2 (or later)]. [https://twitter.com/zettelstore|Stay tuned]… <hr> <h3>Latest Release: 0.0.10 (2021-02-26)</h3> * [./download.wiki|Download] * [./changes.wiki#0_0_10|Change Summary] * [/timeline?p=version-0.0.10&bt=version-0.0.9&y=ci|Check-ins for version 0.0.10], [/vdiff?to=version-0.0.10&from=version-0.0.9|content diff] * [/timeline?df=version-0.0.10&y=ci|Check-ins derived from the 0.0.10 release], [/vdiff?from=version-0.0.10&to=trunk|content diff] * [./plan.wiki|Limitations and planned Improvements] * [/timeline?t=release|Timeline of all past releases] <hr> <h2>Build instructions</h2> Just install [https://fossil-scm.org|Fossil], [https://golang.org/dl/|Go] and some Go-based tools. Please read the [./build.md|instructions] for details. * [/dir?ci=trunk|Source Code] * [/download|Download the source code] as a Tarball or a ZIP file (you must [/login|login] as user "anonymous"). |
Changes to www/plan.wiki.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <title>Limitations and planned Improvements</title> Here is a list of some shortcomings of Zettelstore. They are planned to be solved. <h3>Serious limitations</h3> * Content with binary data (e.g. a GIF, PNG, or JPG file) cannot be created nor modified via the standard web interface. As a workaround, you should place your file into the directory where your zettel are stored. Make sure that the file name starts with unique 14 digits that make up the zettel identifier. * Automatic lists and transclusions are not supported in Zettelmarkup. * … <h3>Smaller limitations</h3> * Quoted attribute values are not yet supported in Zettelmarkup: <code>{key="value with space"}</code>. * The <tt>file</tt> sub-command currently does not support output format “json”. | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <title>Limitations and planned Improvements</title> Here is a list of some shortcomings of Zettelstore. They are planned to be solved. <h3>Serious limitations</h3> * Content with binary data (e.g. a GIF, PNG, or JPG file) cannot be created nor modified via the standard web interface. As a workaround, you should place your file into the directory where your zettel are stored. Make sure that the file name starts with unique 14 digits that make up the zettel identifier. * Automatic lists and transclusions are not supported in Zettelmarkup. * The search function uses only the metadata of a zettel, not its content. * … <h3>Smaller limitations</h3> * Quoted attribute values are not yet supported in Zettelmarkup: <code>{key="value with space"}</code>. * The <tt>file</tt> sub-command currently does not support output format “json”. |
︙ | ︙ |