Index: LICENSE.txt ================================================================== --- LICENSE.txt +++ LICENSE.txt @@ -1,6 +1,6 @@ -Copyright (c) 2020-2023 Detlef Stern +Copyright (c) 2020-2022 Detlef Stern Licensed under the EUPL Zettelstore is licensed under the European Union Public License, version 1.2 or later (EUPL v. 1.2). The license is available in the official languages of the Index: VERSION ================================================================== --- VERSION +++ VERSION @@ -1,1 +1,1 @@ -0.10.1 +0.9.0 Index: ast/block.go ================================================================== --- ast/block.go +++ ast/block.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -279,14 +279,14 @@ //-------------------------------------------------------------------------- // BLOBNode contains just binary data that must be interpreted according to // a syntax. type BLOBNode struct { - Description InlineSlice - Syntax string - Blob []byte + Title string + Syntax string + Blob []byte } func (*BLOBNode) blockNode() { /* Just a marker */ } // WalkChildren does nothing. func (*BLOBNode) WalkChildren(Visitor) { /* No children*/ } Index: box/constbox/form.mustache ================================================================== --- box/constbox/form.mustache +++ box/constbox/form.mustache @@ -1,10 +1,10 @@

{{Heading}}

-
+
Index: box/constbox/info.mustache ================================================================== --- box/constbox/info.mustache +++ box/constbox/info.mustache @@ -9,13 +9,11 @@ {{#CanFolge}} · Folge{{/CanFolge}} {{#CanRename}}· Rename{{/CanRename}} {{#CanDelete}}· Delete{{/CanDelete}}

Interpreted Metadata

- -{{#MetaData}} -{{/MetaData}}
{{Key}}{{{Value}}}
+{{#MetaData}}{{/MetaData}}
{{Key}}{{{Value}}}

References

{{#HasLocLinks}}

Local

    {{#LocLinks}} @@ -49,21 +47,21 @@

    Parts and encodings

    {{#EvalMatrix}} -{{#Elements}} +{{#Elements}} {{/Elements}} {{/EvalMatrix}}
    {{Header}}{{Text}}{{Text}}

    Parsed (not evaluated)

    {{#ParseMatrix}} -{{#Elements}} +{{#Elements}} {{/Elements}} {{/ParseMatrix}}
    {{Header}}{{Text}}{{Text}}
    {{#HasShadowLinks}} Index: box/constbox/license.txt ================================================================== --- box/constbox/license.txt +++ box/constbox/license.txt @@ -1,6 +1,6 @@ -Copyright (c) 2020-2023 Detlef Stern +Copyright (c) 2020-2022 Detlef Stern Licensed under the EUPL Zettelstore is licensed under the European Union Public License, version 1.2 or later (EUPL v. 1.2). The license is available in the official languages of the Index: box/constbox/listzettel.mustache ================================================================== --- box/constbox/listzettel.mustache +++ box/constbox/listzettel.mustache @@ -3,10 +3,5 @@ {{{Content}}} -{{#CanCreate}}
    - - - -
    {{/CanCreate}} Index: box/dirbox/dirbox.go ================================================================== --- box/dirbox/dirbox.go +++ box/dirbox/dirbox.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -179,14 +179,14 @@ for _, c := range dp.fCmds { close(c) } } -func (dp *dirBox) notifyChanged(zid id.Zid) { +func (dp *dirBox) notifyChanged(reason box.UpdateReason, zid id.Zid) { if chci := dp.cdata.Notify; chci != nil { - dp.log.Trace().Zid(zid).Msg("notifyChanged") - chci <- box.UpdateInfo{Reason: box.OnZettel, Zid: zid} + dp.log.Trace().Zid(zid).Uint("reason", uint64(reason)).Msg("notifyChanged") + chci <- box.UpdateInfo{Reason: reason, Zid: zid} } } func (dp *dirBox) getFileChan(zid id.Zid) chan fileCmd { // Based on https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function @@ -220,11 +220,11 @@ err = dp.srvSetZettel(ctx, &entry, zettel) if err == nil { err = dp.dirSrv.UpdateDirEntry(&entry) } - dp.notifyChanged(meta.Zid) + dp.notifyChanged(box.OnZettel, meta.Zid) dp.log.Trace().Err(err).Zid(meta.Zid).Msg("CreateZettel") return meta.Zid, err } func (dp *dirBox) GetZettel(ctx context.Context, zid id.Zid) (domain.Zettel, error) { @@ -305,11 +305,11 @@ } dp.updateEntryFromMetaContent(entry, meta, zettel.Content) dp.dirSrv.UpdateDirEntry(entry) err := dp.srvSetZettel(ctx, entry, zettel) if err == nil { - dp.notifyChanged(zid) + dp.notifyChanged(box.OnZettel, zid) } dp.log.Trace().Zid(zid).Err(err).Msg("UpdateZettel") return err } @@ -354,12 +354,12 @@ dp.dirSrv.RenameDirEntry(&newEntry, curZid) return err } err = dp.srvDeleteZettel(ctx, curEntry, curZid) if err == nil { - dp.notifyChanged(curZid) - dp.notifyChanged(newZid) + dp.notifyChanged(box.OnZettel, curZid) + dp.notifyChanged(box.OnZettel, newZid) } dp.log.Trace().Zid(curZid).Zid(newZid).Err(err).Msg("RenameZettel") return err } @@ -384,11 +384,11 @@ if err != nil { return nil } err = dp.srvDeleteZettel(ctx, entry, zid) if err == nil { - dp.notifyChanged(zid) + dp.notifyChanged(box.OnZettel, zid) } dp.log.Trace().Zid(zid).Err(err).Msg("DeleteZettel") return err } Index: box/filebox/zipbox.go ================================================================== --- box/filebox/zipbox.go +++ box/filebox/zipbox.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2021-2023 Detlef Stern +// Copyright (c) 2021-2022 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 @@ -46,11 +46,14 @@ reader, err := zip.OpenReader(zb.name) if err != nil { return err } reader.Close() - zipNotifier := notify.NewSimpleZipNotifier(zb.log, zb.name) + zipNotifier, err := notify.NewSimpleZipNotifier(zb.log, zb.name) + if err != nil { + return err + } zb.dirSrv = notify.NewDirService(zb.log, zipNotifier, zb.notify) zb.dirSrv.Start() return nil } Index: box/manager/anteroom.go ================================================================== --- box/manager/anteroom.go +++ box/manager/anteroom.go @@ -25,11 +25,11 @@ ) type anteroom struct { num uint64 next *anteroom - waiting id.Set + waiting map[id.Zid]arAction curLoad int reload bool } type anterooms struct { @@ -38,70 +38,76 @@ first *anteroom last *anteroom maxLoad int } -func newAnterooms(maxLoad int) *anterooms { return &anterooms{maxLoad: maxLoad} } +func newAnterooms(maxLoad int) *anterooms { + return &anterooms{maxLoad: maxLoad} +} func (ar *anterooms) EnqueueZettel(zid id.Zid) { if !zid.IsValid() { return } ar.mx.Lock() defer ar.mx.Unlock() if ar.first == nil { - ar.first = ar.makeAnteroom(zid) + ar.first = ar.makeAnteroom(zid, arZettel) ar.last = ar.first return } for room := ar.first; room != nil; room = room.next { if room.reload { continue // Do not put zettel in reload room } if _, ok := room.waiting[zid]; ok { - // Zettel is already waiting. Nothing to do. - return + // Zettel is already waiting. Move it to the last room. + if room == ar.last { + return // Nothing to do, is already there. + } + delete(room.waiting, zid) + room.curLoad-- + break } } if room := ar.last; !room.reload && (ar.maxLoad == 0 || room.curLoad < ar.maxLoad) { - room.waiting.Zid(zid) + room.waiting[zid] = arZettel room.curLoad++ return } - room := ar.makeAnteroom(zid) + room := ar.makeAnteroom(zid, arZettel) ar.last.next = room ar.last = room } -func (ar *anterooms) makeAnteroom(zid id.Zid) *anteroom { - ar.nextNum++ - if zid == id.Invalid { - return &anteroom{num: ar.nextNum, next: nil, waiting: nil, curLoad: 0, reload: true} - } +func (ar *anterooms) makeAnteroom(zid id.Zid, action arAction) *anteroom { c := ar.maxLoad if c == 0 { c = 100 } - waiting := id.NewSetCap(ar.maxLoad, zid) + waiting := make(map[id.Zid]arAction, c) + waiting[zid] = action + ar.nextNum++ return &anteroom{num: ar.nextNum, next: nil, waiting: waiting, curLoad: 1, reload: false} } func (ar *anterooms) Reset() { ar.mx.Lock() defer ar.mx.Unlock() - ar.first = ar.makeAnteroom(id.Invalid) + ar.first = ar.makeAnteroom(id.Invalid, arReload) ar.last = ar.first } func (ar *anterooms) Reload(newZids id.Set) uint64 { ar.mx.Lock() defer ar.mx.Unlock() + newWaiting := createWaitingSet(newZids) ar.deleteReloadedRooms() - if ns := len(newZids); ns > 0 { + if ns := len(newWaiting); ns > 0 { ar.nextNum++ - ar.first = &anteroom{num: ar.nextNum, next: ar.first, waiting: newZids, curLoad: ns, reload: true} + ar.first = &anteroom{num: ar.nextNum, next: ar.first, waiting: newWaiting, curLoad: ns} if ar.first.next == nil { ar.last = ar.first } return ar.nextNum } @@ -108,10 +114,20 @@ ar.first = nil ar.last = nil return 0 } + +func createWaitingSet(zids id.Set) map[id.Zid]arAction { + waitingSet := make(map[id.Zid]arAction, len(zids)) + for zid := range zids { + if zid.IsValid() { + waitingSet[zid] = arZettel + } + } + return waitingSet +} func (ar *anterooms) deleteReloadedRooms() { room := ar.first for room != nil && room.reload { room = room.next @@ -126,27 +142,18 @@ ar.mx.Lock() defer ar.mx.Unlock() if ar.first == nil { return arNothing, id.Invalid, 0 } - roomNo := ar.first.num - if ar.first.waiting == nil { - ar.removeFirst() - return arReload, id.Invalid, roomNo - } - for zid := range ar.first.waiting { + for zid, action := range ar.first.waiting { + roomNo := ar.first.num delete(ar.first.waiting, zid) if len(ar.first.waiting) == 0 { - ar.removeFirst() - } - return arZettel, zid, roomNo - } - ar.removeFirst() - return arNothing, id.Invalid, 0 -} - -func (ar *anterooms) removeFirst() { - ar.first = ar.first.next - if ar.first == nil { - ar.last = nil - } + ar.first = ar.first.next + if ar.first == nil { + ar.last = nil + } + } + return action, zid, roomNo + } + return arNothing, id.Invalid, 0 } Index: box/manager/indexer.go ================================================================== --- box/manager/indexer.go +++ box/manager/indexer.go @@ -83,15 +83,14 @@ timerDuration := 15 * time.Second timer := time.NewTimer(timerDuration) ctx := box.NoEnrichContext(context.Background()) for { - // Sleep first, so the indexer will wait for boxes to initialize. + mgr.idxWorkService(ctx) if !mgr.idxSleepService(timer, timerDuration) { return } - mgr.idxWorkService(ctx) } } func (mgr *Manager) idxWorkService(ctx context.Context) { var roomNum uint64 Index: box/manager/manager.go ================================================================== --- box/manager/manager.go +++ box/manager/manager.go @@ -124,11 +124,11 @@ infos: make(chan box.UpdateInfo, len(boxURIs)*10), propertyKeys: propertyKeys, idxLog: boxLog.Clone().Str("box", "index").Child(), idxStore: memstore.New(), - idxAr: newAnterooms(1000), + idxAr: newAnterooms(10), idxReady: make(chan struct{}, 1), } cdata := ConnectData{Number: 1, Config: rtConfig, Enricher: mgr, Notify: mgr.infos} boxes := make([]box.ManagedBox, 0, len(boxURIs)+2) for _, uri := range boxURIs { Index: box/membox/membox.go ================================================================== --- box/membox/membox.go +++ box/membox/membox.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -50,13 +50,13 @@ mx sync.RWMutex // Protects the following fields zettel map[id.Zid]domain.Zettel curBytes int } -func (mb *memBox) notifyChanged(zid id.Zid) { +func (mb *memBox) notifyChanged(reason box.UpdateReason, zid id.Zid) { if chci := mb.cdata.Notify; chci != nil { - chci <- box.UpdateInfo{Reason: box.OnZettel, Zid: zid} + chci <- box.UpdateInfo{Reason: reason, Zid: zid} } } func (mb *memBox) Location() string { return mb.u.String() @@ -102,11 +102,11 @@ meta.Zid = zid zettel.Meta = meta mb.zettel[zid] = zettel mb.curBytes = newBytes mb.mx.Unlock() - mb.notifyChanged(zid) + mb.notifyChanged(box.OnZettel, zid) mb.log.Trace().Zid(zid).Msg("CreateZettel") return zid, nil } func (mb *memBox) GetZettel(_ context.Context, zid id.Zid) (domain.Zettel, error) { @@ -191,11 +191,11 @@ zettel.Meta = m mb.zettel[m.Zid] = zettel mb.curBytes = newBytes mb.mx.Unlock() - mb.notifyChanged(m.Zid) + mb.notifyChanged(box.OnZettel, m.Zid) mb.log.Trace().Msg("UpdateZettel") return nil } func (*memBox) AllowRenameZettel(context.Context, id.Zid) bool { return true } @@ -218,12 +218,12 @@ meta.Zid = newZid zettel.Meta = meta mb.zettel[newZid] = zettel delete(mb.zettel, curZid) mb.mx.Unlock() - mb.notifyChanged(curZid) - mb.notifyChanged(newZid) + mb.notifyChanged(box.OnZettel, curZid) + mb.notifyChanged(box.OnZettel, newZid) mb.log.Trace().Msg("RenameZettel") return nil } func (mb *memBox) CanDeleteZettel(_ context.Context, zid id.Zid) bool { @@ -241,11 +241,11 @@ return box.ErrNotFound } delete(mb.zettel, zid) mb.curBytes -= oldZettel.Length() mb.mx.Unlock() - mb.notifyChanged(zid) + mb.notifyChanged(box.OnZettel, zid) mb.log.Trace().Msg("DeleteZettel") return nil } func (mb *memBox) ReadStats(st *box.ManagedBoxStats) { Index: box/notify/directory.go ================================================================== --- box/notify/directory.go +++ box/notify/directory.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -276,18 +276,18 @@ case Update: ds.mx.Lock() zid := ds.onUpdateFileEvent(ds.entries, ev.Name) ds.mx.Unlock() if zid != id.Invalid { - ds.notifyChange(zid) + ds.notifyChange(box.OnZettel, zid) } case Delete: ds.mx.Lock() zid := ds.onDeleteFileEvent(ds.entries, ev.Name) ds.mx.Unlock() if zid != id.Invalid { - ds.notifyChange(zid) + ds.notifyChange(box.OnZettel, zid) } default: ds.log.Warn().Str("event", fmt.Sprintf("%v", ev)).Msg("Unknown zettel notification event") } return newEntries, true @@ -301,18 +301,18 @@ return zids } func (ds *DirService) onCreateDirectory(zids id.Slice, prevEntries entrySet) { for _, zid := range zids { - ds.notifyChange(zid) + ds.notifyChange(box.OnZettel, zid) delete(prevEntries, zid) } // These were previously stored, by are not found now. // Notify system that these were deleted, e.g. for updating the index. for zid := range prevEntries { - ds.notifyChange(zid) + ds.notifyChange(box.OnZettel, zid) } } func (ds *DirService) onDestroyDirectory() { ds.mx.Lock() @@ -319,11 +319,11 @@ entries := ds.entries ds.entries = nil ds.state = dsMissing ds.mx.Unlock() for zid := range entries { - ds.notifyChange(zid) + ds.notifyChange(box.OnZettel, zid) } } var validFileName = regexp.MustCompile(`^(\d{14})`) @@ -590,11 +590,11 @@ return newLen < oldLen } return newExt < oldExt } -func (ds *DirService) notifyChange(zid id.Zid) { +func (ds *DirService) notifyChange(reason box.UpdateReason, zid id.Zid) { if chci := ds.infos; chci != nil { - ds.log.Trace().Zid(zid).Msg("notifyChange") - chci <- box.UpdateInfo{Reason: box.OnZettel, Zid: zid} + ds.log.Trace().Zid(zid).Uint("reason", uint64(reason)).Msg("notifyChange") + chci <- box.UpdateInfo{Reason: reason, Zid: zid} } } Index: box/notify/simpledir.go ================================================================== --- box/notify/simpledir.go +++ box/notify/simpledir.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2021-2023 Detlef Stern +// Copyright (c) 2021-2022 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 @@ -42,20 +42,20 @@ return sdn, nil } // NewSimpleZipNotifier creates a zip-file based notifier that will not receive // any notifications from the operating system. -func NewSimpleZipNotifier(log *logger.Logger, zipPath string) Notifier { +func NewSimpleZipNotifier(log *logger.Logger, zipPath string) (Notifier, error) { sdn := &simpleDirNotifier{ log: log, events: make(chan Event), done: make(chan struct{}), refresh: make(chan struct{}), fetcher: newZipPathFetcher(zipPath), } go sdn.eventLoop() - return sdn + return sdn, nil } func (sdn *simpleDirNotifier) Events() <-chan Event { return sdn.events } Index: cmd/cmd_run.go ================================================================== --- cmd/cmd_run.go +++ cmd/cmd_run.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -92,12 +92,10 @@ // Web user interface if !authManager.IsReadonly() { webSrv.AddZettelRoute('b', server.MethodGet, wui.MakeGetRenameZettelHandler( ucGetMeta, &ucEvaluate)) webSrv.AddZettelRoute('b', server.MethodPost, wui.MakePostRenameZettelHandler(&ucRename)) - webSrv.AddListRoute('c', server.MethodGet, wui.MakeGetZettelFromListHandler(ucListMeta, &ucEvaluate, ucListRoles, ucListSyntax)) - webSrv.AddListRoute('c', server.MethodPost, wui.MakePostCreateZettelHandler(&ucCreateZettel)) webSrv.AddZettelRoute('c', server.MethodGet, wui.MakeGetCreateZettelHandler( ucGetZettel, &ucCreateZettel, ucListRoles, ucListSyntax)) webSrv.AddZettelRoute('c', server.MethodPost, wui.MakePostCreateZettelHandler(&ucCreateZettel)) webSrv.AddZettelRoute('d', server.MethodGet, wui.MakeGetDeleteZettelHandler( ucGetMeta, ucGetAllMeta, &ucEvaluate)) @@ -105,11 +103,12 @@ webSrv.AddZettelRoute('e', server.MethodGet, wui.MakeEditGetZettelHandler(ucGetZettel, ucListRoles, ucListSyntax)) webSrv.AddZettelRoute('e', server.MethodPost, wui.MakeEditSetZettelHandler(&ucUpdate)) } webSrv.AddListRoute('g', server.MethodGet, wui.MakeGetGoActionHandler(&ucRefresh)) webSrv.AddListRoute('h', server.MethodGet, wui.MakeListHTMLMetaHandler(ucListMeta, &ucEvaluate)) - webSrv.AddZettelRoute('h', server.MethodGet, wui.MakeGetHTMLZettelHandler(&ucEvaluate, ucGetMeta)) + webSrv.AddZettelRoute('h', server.MethodGet, wui.MakeGetHTMLZettelHandler( + &ucEvaluate, ucGetMeta)) webSrv.AddListRoute('i', server.MethodGet, wui.MakeGetLoginOutHandler()) webSrv.AddListRoute('i', server.MethodPost, wui.MakePostLoginHandler(&ucAuthenticate)) webSrv.AddZettelRoute('i', server.MethodGet, wui.MakeGetInfoHandler( ucParseZettel, &ucEvaluate, ucGetMeta, ucGetAllMeta, ucUnlinkedRefs)) webSrv.AddZettelRoute('k', server.MethodGet, wui.MakeZettelContextHandler( @@ -116,22 +115,32 @@ ucZettelContext, &ucEvaluate)) // API webSrv.AddListRoute('a', server.MethodPost, a.MakePostLoginHandler(&ucAuthenticate)) webSrv.AddListRoute('a', server.MethodPut, a.MakeRenewAuthHandler()) + webSrv.AddListRoute('j', server.MethodGet, a.MakeQueryHandler(ucListMeta)) + webSrv.AddZettelRoute('j', server.MethodGet, a.MakeGetZettelHandler(ucGetZettel)) + webSrv.AddZettelRoute('m', server.MethodGet, a.MakeGetMetaHandler(ucGetMeta)) webSrv.AddZettelRoute('o', server.MethodGet, a.MakeGetOrderHandler( usecase.NewZettelOrder(protectedBoxManager, ucEvaluate))) + webSrv.AddZettelRoute('p', server.MethodGet, a.MakeGetParsedZettelHandler(ucParseZettel)) + webSrv.AddListRoute('q', server.MethodGet, a.MakeQueryHandler(ucListMeta)) webSrv.AddZettelRoute('u', server.MethodGet, a.MakeListUnlinkedMetaHandler( ucGetMeta, ucUnlinkedRefs, &ucEvaluate)) + webSrv.AddZettelRoute('v', server.MethodGet, a.MakeGetEvalZettelHandler(ucEvaluate)) webSrv.AddListRoute('x', server.MethodGet, a.MakeGetDataHandler(ucVersion)) webSrv.AddListRoute('x', server.MethodPost, a.MakePostCommandHandler(&ucIsAuth, &ucRefresh)) webSrv.AddZettelRoute('x', server.MethodGet, a.MakeZettelContextHandler(ucZettelContext)) - webSrv.AddListRoute('z', server.MethodGet, a.MakeQueryHandler(ucListMeta)) - webSrv.AddZettelRoute('z', server.MethodGet, a.MakeGetZettelHandler(ucGetMeta, ucGetZettel, ucParseZettel, ucEvaluate)) + webSrv.AddListRoute('z', server.MethodGet, a.MakeListPlainHandler(ucListMeta)) + webSrv.AddZettelRoute('z', server.MethodGet, a.MakeGetPlainZettelHandler(ucGetZettel)) if !authManager.IsReadonly() { - webSrv.AddListRoute('z', server.MethodPost, a.MakePostCreateZettelHandler(&ucCreateZettel)) - webSrv.AddZettelRoute('z', server.MethodPut, a.MakeUpdateZettelHandler(&ucUpdate)) + webSrv.AddListRoute('j', server.MethodPost, a.MakePostCreateZettelHandler(&ucCreateZettel)) + webSrv.AddZettelRoute('j', server.MethodPut, a.MakeUpdateZettelHandler(&ucUpdate)) + webSrv.AddZettelRoute('j', server.MethodDelete, a.MakeDeleteZettelHandler(&ucDelete)) + webSrv.AddZettelRoute('j', server.MethodMove, a.MakeRenameZettelHandler(&ucRename)) + webSrv.AddListRoute('z', server.MethodPost, a.MakePostCreatePlainZettelHandler(&ucCreateZettel)) + webSrv.AddZettelRoute('z', server.MethodPut, a.MakeUpdatePlainZettelHandler(&ucUpdate)) webSrv.AddZettelRoute('z', server.MethodDelete, a.MakeDeleteZettelHandler(&ucDelete)) webSrv.AddZettelRoute('z', server.MethodMove, a.MakeRenameZettelHandler(&ucRename)) } if authManager.WithAuth() { Index: config/config.go ================================================================== --- config/config.go +++ config/config.go @@ -17,10 +17,11 @@ "zettelstore.de/z/domain/meta" ) // Key values that are supported by Config.Get const ( + KeyFooterHTML = "footer-html" KeyFooterZettel = "footer-zettel" KeyHomeZettel = "home-zettel" // api.KeyLang KeyMarkerExternal = "marker-external" ) Index: docs/development/20210916193200.zettel ================================================================== --- docs/development/20210916193200.zettel +++ docs/development/20210916193200.zettel @@ -1,22 +1,19 @@ id: 20210916193200 title: Required Software role: zettel syntax: zmk -created: 20210916193200 -modified: 20230109121417 +modified: 20211213190428 The following software must be installed: -* A current, supported [[release of Go|https://go.dev/doc/devel/release]], +* A current, supported [[release of Go|https://golang.org/doc/devel/release.html]], * [[shadow|https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/shadow]] via ``go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest``, * [[staticcheck|https://staticcheck.io/]] via ``go install honnef.co/go/tools/cmd/staticcheck@latest``, -* [[unparam|https://mvdan.cc/unparam]][^[[GitHub|https://github.com/mvdan/unparam]]] via ``go install mvdan.cc/unparam@latest``, -* [[Fossil|https://fossil-scm.org/]], -* [[Git|https://git-scm.org/]] (most dependencies are accessible via Git only). +* [[unparam|https://mvdan.cc/unparam]][^[[GitHub|https://github.com/mvdan/unparam]]] via ``go install mvdan.cc/unparam@latest`` Make sure that the software is in your path, e.g. via: ```sh export PATH=$PATH:/usr/local/go/bin export PATH=$PATH:$(go env GOPATH)/bin ``` Index: docs/manual/00001004020000.zettel ================================================================== --- docs/manual/00001004020000.zettel +++ docs/manual/00001004020000.zettel @@ -2,11 +2,11 @@ title: Configure the running Zettelstore role: manual tags: #configuration #manual #zettelstore syntax: zmk created: 20210126175322 -modified: 20221219175720 +modified: 20221205162058 You can configure a running Zettelstore by modifying the special zettel with the ID [[00000000000100]]. This zettel is called __configuration zettel__. The following metadata keys change the appearance / behavior of Zettelstore. Some of them can be overwritten in an [[user zettel|00001010040200]], a subset of those may be overwritten in zettel that is currently used. @@ -26,23 +26,31 @@ Default: ""login"". ; [!expert-mode|''expert-mode''] : If set to a [[boolean true value|00001006030500]], all zettel with [[visibility ""expert""|00001010070200]] will be shown (to the owner, if [[authentication is enabled|00001010040100]]; to all, otherwise). This affects most computed zettel. Default: ""False"". +; [!footer-html|''footer-html''] +: Contains some HTML code that will be included into the footer of each Zettelstore web page. + It only affects the [[web user interface|00001014000000]]. + Zettel content, delivered via the [[API|00001012000000]] as JSON, etc. is not affected. + + May be overwritten in a user zettel. + + Default: (the empty string). ; [!footer-zettel|''footer-zettel''] : Identifier of a zettel that is rendered as HTML and will be placed as the footer of every zettel in the [[web user interface|00001014000000]]. Zettel content, delivered via the [[API|00001012000000]] as JSON, etc. is not affected. - If the zettel identifier is invalid or references a zettel that could not be read (possibly because of a limited [[visibility setting|00001010070200]]), nothing is written as the footer. + If the zettel identifier is invalid or references a zettel that could not be read, nothing is placed as the footer. - May be [[overwritten|00001004020200]] in a user zettel. + May be overwritten in a user zettel. Default: (an invalid zettel identifier) ; [!home-zettel|''home-zettel''] : Specifies the identifier of the zettel, that should be presented for the default view / home view. If not given or if the identifier does not identify a zettel, the zettel with the identifier ''00010000000000'' is shown. - May be [[overwritten|00001004020200]] in a user zettel. + May be overwritten in a user zettel. ; [!lang|''lang''] : Language to be used when displaying content. Default: ""en"". @@ -52,11 +60,11 @@ Use values according to the language definition of [[RFC-5646|https://tools.ietf.org/html/rfc5646]]. ; [!marker-external|''marker-external''] : Some HTML code that is displayed after a [[reference to external material|00001007040310]]. - May be [[overwritten|00001004020200]] in a user zettel. + May be overwritten in a user zettel. Default: ""&\#10138;"", to display a ""➚"" sign. ; [!max-transclusions|''max-transclusions''] : Maximum number of indirect transclusion. This is used to avoid an exploding ""transclusion bomb"", a form of a [[billion laughs attack|https://en.wikipedia.org/wiki/Billion_laughs_attack]]. Index: docs/manual/00001004020200.zettel ================================================================== --- docs/manual/00001004020200.zettel +++ docs/manual/00001004020200.zettel @@ -2,18 +2,19 @@ title: Runtime configuration data that may be user specific or zettel specific role: manual tags: #configuration #manual #zettelstore syntax: zmk created: 20221205155521 -modified: 20221212195530 +modified: 20221205161720 Some metadata of the [[runtime configuration|00001004020000]] may be overwritten in an [[user zettel|00001010040200]]. A subset of those may be overwritten in zettel that is currently used. This allows to specify user specific or zettel specific behavior. The following metadata keys are supported to provide a more specific behavior: |=Key|User:|Zettel:|Remarks +|[[''footer-html''|00001004020000#footer-html]]|Y|N|Will be removed in v0.10.0 |[[''footer-zettel''|00001004020000#footer-zettel]]|Y|N| |[[''home-zettel''|00001004020000#home-zettel]]|Y|N| |[[''lang''|00001004020000#lang]]|Y|Y|Making it user-specific could make zettel for other user less useful |[[''marker-external''|00001004020000#marker-external]]|Y|Y| Index: docs/manual/00001004051200.zettel ================================================================== --- docs/manual/00001004051200.zettel +++ docs/manual/00001004051200.zettel @@ -2,11 +2,11 @@ title: The ''file'' sub-command role: manual tags: #command #configuration #manual #zettelstore syntax: zmk created: 20210126175322 -modified: 20230109105434 +modified: 20221107183235 Reads zettel data from a file (or from standard input / stdin) and renders it to standard output / stdout. This allows Zettelstore to render files manually. ``` zettelstore file [-t FORMAT] [file-1 [file-2]] @@ -17,14 +17,14 @@ Supported values are: [[''html''|00001012920510]] (default), [[''md''|00001012920513]], [[''sexpr''|00001012920516]], [[''text''|00001012920519]], - [[''zjson''|00001012920503]] (deprecated in v0.11), + [[''zjson''|00001012920503]], and [[''zmk''|00001012920522]]. ; ''file-1'' : Specifies the file name, where at least metadata is read. If ''file-2'' is not given, the zettel content is also read from here. ; ''file-2'' : File name where the zettel content is stored. If neither ''file-1'' nor ''file-2'' are given, metadata and zettel content are read from standard input / stdin. Index: docs/manual/00001006000000.zettel ================================================================== --- docs/manual/00001006000000.zettel +++ docs/manual/00001006000000.zettel @@ -1,12 +1,11 @@ id: 00001006000000 title: Layout of a Zettel role: manual tags: #design #manual #zettelstore syntax: zmk -created: 20210126175322 -modified: 20221219162703 +modified: 20220724165931 A zettel consists of two parts: the metadata and the zettel content. Metadata gives some information mostly about the zettel content, how it should be interpreted, how it is sorted within Zettelstore. The zettel content is, well, the actual content. In many cases, the content is in plain text form. @@ -28,22 +27,22 @@ Other character encodings are not supported and will never be[^This is not a real problem, since every modern software should support UTF-8 as an encoding.]. There is support for a graphical format with a text representation: SVG. And there is support for some binary image formats, like GIF, PNG, and JPEG. === Plain, parsed, and evaluated zettel -Zettelstore may present your zettel in various forms, typically retrieved with the [[endpoint|00001012920000]] ''/z/{ID}''. +Zettelstore may present your zettel in various forms. One way is to present the zettel as it was read by Zettelstore. -This is called ""[[plain zettel|00001003000000]]"". +This is called ""[[plain zettel|00001003000000#plain]]"", typically retrieved with the [[endpoint|00001012920000]] ''/z/{ID}''. The second way is to present the zettel as it was recognized by Zettelstore. -This is called ""[[parsed zettel|00001012053600]]"", also retrieved with the [[endpoint|00001012920000]] ''/z/{ID}'', but with additional query parameter. +This is called ""[[parsed zettel|00001012053600]]"", typically retrieved with the [[endpoint|00001012920000]] ''/p/{ID}''. Such a zettel was read and analyzed. It can be presented in various [[encodings|00001012920500]].[^The [[zmk encoding|00001012920522]] allows you to compare the plain, the parsed, and the evaluated form of a zettel.] -However, a zettel such as this one you are currently reading, is a ""[[evaluated zettel|00001012053500]]"", also retrieved with the [[endpoint|00001012920000]] ''/z/{ID}'' and specifying an encoding. +However, a zettel such as this one you are currently reading, is a ""[[evaluated zettel|00001012053500]]"", typically retrieved with the [[endpoint|00001012920000]] ''/v/{ID}''. The biggest difference to a parsed zettel is the inclusion of [[block transclusions|00001007031100]] or [[inline transclusions|00001007040324]] for an evaluated zettel. It can also be presented in various encoding, including the ""zmk"" encoding. Evaluations also applies to metadata of a zettel, if appropriate. Please note, that searching for content is based on parsed zettel. Transcluded content will only be found in transcluded zettel, but not in the zettel that transcluded the content. However, you will easily pick up that zettel by follow the [[backward|00001006020000#backward]] metadata key of the transcluded zettel. Index: docs/manual/00001007031140.zettel ================================================================== --- docs/manual/00001007031140.zettel +++ docs/manual/00001007031140.zettel @@ -2,11 +2,11 @@ title: Zettelmarkup: Query Transclusion role: manual tags: #manual #search #zettelmarkup #zettelstore syntax: zmk created: 20220809132350 -modified: 20230116183656 +modified: 20221014164027 A query transclusion is specified by the following sequence, starting at the first position in a line: ''{{{query:query-expression}}}''. The line must literally start with the sequence ''{{{query:''. Everything after this prefix is interpreted as a [[query expression|00001007700000]]. @@ -45,19 +45,16 @@ : Transform the zettel list into an [[Atom 1.0|https://www.rfc-editor.org/rfc/rfc4287]]-conformant document / feed. The document is embedded into the referencing zettel. ; ''RSS'' (aggregate) : Transform the zettel list into a [[RSS 2.0|https://www.rssboard.org/rss-specification]]-conformant document / feed. The document is embedded into the referencing zettel. -; ''KEYS'' (aggregate) -: Emit a list of all metadata keys, together with the number of zettel having the key. ; Any [[metadata key|00001006020000]] of type [[Word|00001006035500]], [[WordSet|00001006036000]], or [[TagSet|00001006034000]] (aggregates) : Emit an aggregate of the given metadata key. - The key can be given in any letter case[^Except if the key name collides with one of the above names. In this case use at least one lower case letter.]. + The key can be given in any letter case. -Example: ```zmk {{{query:tags:#search | tags}}} ``` This is a tag cloud of all tags that are used together with the tag #search: :::example {{{query:tags:#search | tags}}} ::: Index: docs/manual/00001007031300.zettel ================================================================== --- docs/manual/00001007031300.zettel +++ docs/manual/00001007031300.zettel @@ -2,21 +2,21 @@ title: Zettelmarkup: Evaluation Blocks role: manual tags: #manual #zettelmarkup #zettelstore syntax: zmk created: 20220310184916 -modified: 20230109105402 +modified: 20221026133648 Evaluation blocks are used to enter text that could be evaluated by either Zettelstore or external software. They begin with at least three tilde characters (""''~''"", U+007E) at the first position of a line. You can add some [[attributes|00001007050000]] on the beginning line of a verbatim block, following the initiating characters. The evaluation block supports the default attribute[^Depending on the syntax value.]: when given, all spaces in the text are rendered in HTML as open box characters (U+2423). If you want to give only one attribute and this attribute is the generic attribute, you can omit the most of the attribute syntax and just specify the value. It will be interpreted as a [[syntax|00001008000000]] value to evaluate its content. Not all syntax values are supported by Zettelstore.[^Currently just ""[[draw|00001008050000]]"".] -The main reason for an evaluation block is to be used with external software via the [[Sexpr encoding|00001012920516]]. +The main reason for an evaluation block is to be used with external software via the [[Sexpr encoding|00001012920516]] or the [[ZJSON encoding|00001012920503]]. Any other character in this line will be ignored Text following the beginning line will not be interpreted, until a line begins with at least the same number of the same characters given at the beginning line. This allows to enter some tilde characters in the text that should not be interpreted. Index: docs/manual/00001007031400.zettel ================================================================== --- docs/manual/00001007031400.zettel +++ docs/manual/00001007031400.zettel @@ -1,12 +1,11 @@ id: 00001007031400 title: Zettelmarkup: Math-mode Blocks role: manual tags: #manual #zettelmarkup #zettelstore syntax: zmk -created: 20220311173226 -modified: 20230109105340 +modified: 20220311182505 Math-mode blocks are used to enter mathematical formulas / equations in a display style mode. Similar to a [[evaluation blocks|00001007031300]], the block content will be interpreted by either Zettelstore or an external software. They begin with at least three dollar sign characters (""''$''"", U+0024) at the first position of a line. @@ -14,11 +13,11 @@ A math-mode block supports the default attribute[^Depending on the syntax value.]: when given, all spaces in the text are rendered in HTML as open box characters (U+2423). If you want to give only one attribute and this attribute is the generic attribute, you can omit the most of the attribute syntax and just specify the value. It will be interpreted as a [[syntax|00001008000000]] value to evaluate its content. Alternatively, you could provide an attribute with the key ""syntax"" and use the value to specify the syntax. Not all syntax values are supported by Zettelstore.[^Currently: none.] -External software might support several values via the [[Sexpr encoding|00001012920516]]. +External software might support several values via the [[ZJSON encoding|00001012920503]]. Any other character in this line will be ignored Text following the beginning line will not be interpreted, until a line begins with at least the same number of the same characters given at the beginning line. This allows to enter some dollar-sign characters in the text that should not be interpreted. Index: docs/manual/00001012000000.zettel ================================================================== --- docs/manual/00001012000000.zettel +++ docs/manual/00001012000000.zettel @@ -2,11 +2,11 @@ title: API role: manual tags: #api #manual #zettelstore syntax: zmk created: 20210126175322 -modified: 20221219150243 +modified: 20220923105117 The API (short for ""**A**pplication **P**rogramming **I**nterface"") is the primary way to communicate with a running Zettelstore. Most integration with other systems and services is done through the API. The [[web user interface|00001014000000]] is just an alternative, secondary way of interacting with a Zettelstore. @@ -20,12 +20,12 @@ * [[Authenticate an user|00001012050200]] to obtain an access token * [[Renew an access token|00001012050400]] without costly re-authentication * [[Provide an access token|00001012050600]] when doing an API call === Zettel lists -* [[List all zettel|00001012051200]] * [[Query the list of all zettel|00001012051400]] +* [[List plain text titles of all zettel|00001012051200]] === Working with zettel * [[Create a new zettel|00001012053200]] * [[Retrieve metadata and content of an existing zettel|00001012053300]] * [[Retrieve metadata of an existing zettel|00001012053400]] Index: docs/manual/00001012051200.zettel ================================================================== --- docs/manual/00001012051200.zettel +++ docs/manual/00001012051200.zettel @@ -1,132 +1,63 @@ id: 00001012051200 -title: API: List all zettel +title: API: List plain text titles of all or some zettel role: manual tags: #api #manual #zettelstore syntax: zmk created: 20210126175322 -modified: 20221219154400 +modified: 20220923105412 -To list all zettel just send a HTTP GET request to the [[endpoint|00001012920000]] ''/z''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. -Always use the endpoint ''/z'' to work with a list of zettel. +To list the plain text titles of all zettel just send a HTTP GET request to the [[endpoint|00001012920000]] ''/z''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. -Without further specifications, a plain text document is returned, with one line per zettel. +A plain text document is returned, with one line per zettel. Each line contains in the first 14 characters the [[zettel identifier|00001006050000]]. Separated by a space character, the title of the zettel follows: ```sh # curl http://127.0.0.1:23123/z -... -00001012051200 API: List all zettel +00001012051200 API: Renew an access token 00001012050600 API: Provide an access token 00001012050400 API: Renew an access token 00001012050200 API: Authenticate a client +00001012000000 API +``` + +The query parameter ""''q''"" allows you to specify [[query expressions|00001007700000]] for a full-text search of all zettel content and/or restricting the search according to specific metadata, similar to endpoint ''/q'' to [[query zettel|00001012051400]]. + +You are allowed to specify this query parameter more than once. + +This parameter loosely resembles the search form of the [[web user interface|00001014000000]]. + +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?q=title%3AAPI' +00001012921000 API: JSON structure of an access token +00001012920500 Formats available by the API +00001012920000 Endpoints used by the API +... +``` + +An implicit precondition is that the zettel must contain the given metadata key. +For a metadata key like [[''title''|00001006020000#title]], which has a default value, this precondition should always be true. +But the situation is different for a key like [[''url''|00001006020000#url]]. +Both ``curl 'http://localhost:23123/z?q=url%3A'`` and ``curl 'http://localhost:23123/z?q=url%3A!'`` may result in an empty list. + +Alternatively, you also can use the [[endpoint|00001012920000]] ''/z'' for a simpler result format. +The first example translates to: +```sh +# curl 'http://127.0.0.1:23123/z?q=title%3AAPI' +00001012921000 API: JSON structure of an access token +00001012920500 Formats available by the API +00001012920000 Endpoints used by the API ... ``` -Alternatively, you may retrieve the list of all zettel as a JSON object by specifying the encoding with the query parameter ''enc=json'': - -```sh -# curl 'http://127.0.0.1:23123/z?enc=json' -{"query":"","human":"","list":[{"id":"00001012051200","meta":{"back":"00001012000000","backward":"00001012000000 00001012920000","box-number":"1","created":"20210126175322","forward":"00001006020000 00001006050000 00001007700000 00001010040100 00001012050200 00001012051400 00001012920000 00001012921000 00001014000000","modified":"20221219150626","published":"20221219150626","role":"manual","syntax":"zmk","tags":"#api #manual #zettelstore","title":"API: List all zettel"},"rights":62},{"id":"00001012050600","meta":{"back":"00001012000000 00001012080500","backward":"00001012000000 00001012080500","box-number":"1","created":"00010101000000","forward":"00001012050200 00001012921000","modified":"20220218130020","published":"20220218130020","role":"manual","syntax":"zmk","tags":"#api #manual #zettelstore","title":"API: Provide an access token"},"rights":62},{"id":"00001012050400","meta":{"back":"00001010040700 00001012000000","backward":"00001010040700 00001012000000 00001012920000 00001012921000","box-number":"1","created":"00010101000000","forward":"00001010040100 00001012050200 00001012920000 00001012921000","modified":"20220107215751","published":"20220107215751","role":"manual","syntax":"zmk","tags":"#api #manual #zettelstore","title":"API: Renew an access token"},"rights":62},{"id":"00001012050200","meta":{"back":"00001012000000 00001012050400 00001012050600 00001012051200 00001012051400 00001012053300 00001012053400 00001012053500 00001012053600 00001012080200","backward":"00001010040700 00001012000000 00001012050400 00001012050600 00001012051200 00001012051400 00001012053300 00001012053400 00001012053500 00001012053600 00001012080200 00001012920000 00001012921000","box-number":"1","created":"00010101000000","forward":"00001004010000 00001010040100 00001010040200 00001010040700 00001012920000 00001012921000","modified":"20220107215844","published":"20220107215844","role":"manual","syntax":"zmk","tags":"#api #manual #zettelstore","title":"API: Authenticate a client"},"rights":62}, ...]} -``` - -If you reformat the JSON output, you will see its structure better: -``` -{ - "query": "", - "human": "", - "list": [ - { - "id": "00001012051200", - "meta": { - "back": "00001012000000", - "backward": "00001012000000 00001012920000", - "box-number": "1", - "created": "20210126175322", - "forward": "00001006020000 00001006050000 00001007700000 00001010040100 00001012050200 00001012051400 00001012920000 00001012921000 00001014000000", - "modified": "20221219151200", - "published": "20221219151200", - "role": "manual", - "syntax": "zmk", - "tags": "#api #manual #zettelstore", - "title": "API: List all zettel" - }, - "rights": 62 - }, - { - "id": "00001012050600", - "meta": { - "back": "00001012000000 00001012080500", - "backward": "00001012000000 00001012080500", - "box-number": "1", - "created": "00010101000000", - "forward": "00001012050200 00001012921000", - "modified": "20220218130020", - "published": "20220218130020", - "role": "manual", - "syntax": "zmk", - "tags": "#api #manual #zettelstore", - "title": "API: Provide an access token" - }, - "rights": 62 - }, - { - "id": "00001012050400", - "meta": { - "back": "00001010040700 00001012000000", - "backward": "00001010040700 00001012000000 00001012920000 00001012921000", - "box-number": "1", - "created": "00010101000000", - "forward": "00001010040100 00001012050200 00001012920000 00001012921000", - "modified": "20220107215751", - "published": "20220107215751", - "role": "manual", - "syntax": "zmk", - "tags": "#api #manual #zettelstore", - "title": "API: Renew an access token" - }, - "rights": 62 - }, - { - "id": "00001012050200", - "meta": { - "back": "00001012000000 00001012050400 00001012050600 00001012051200 00001012051400 00001012053300 00001012053400 00001012053500 00001012053600 00001012 -080200", - "backward": "00001010040700 00001012000000 00001012050400 00001012050600 00001012051200 00001012051400 00001012053300 00001012053400 00001012053500 0000 -1012053600 00001012080200 00001012920000 00001012921000", - "box-number": "1", - "created": "00010101000000", - "forward": "00001004010000 00001010040100 00001010040200 00001010040700 00001012920000 00001012921000", - "modified": "20220107215844", - "published": "20220107215844", - "role": "manual", - "syntax": "zmk", - "tags": "#api #manual #zettelstore", - "title": "API: Authenticate a client" - }, - "rights": 62 - } - ] -} -``` - -The JSON object contains a key ''"list"'' where its value is a list of zettel JSON objects. -These zettel JSON objects themselves contains the keys ''"id"'' (value is a string containing the [[zettel identifier|00001006050000]]), ''"meta"'' (value as a JSON object), and ''"rights"'' (encodes the [[access rights|00001012921200]] for the given zettel). -The value of key ''"meta"'' effectively contains all metadata of the identified zettel, where metadata keys are encoded as JSON object keys and metadata values encoded as JSON strings. - -The JSON objects keys ''"query"'' and ''"human"'' will be explained later in this manual. - -=== Note -This request (and similar others) will always return a list of metadata, provided the request was syntactically correct. -There will never be a HTTP status code 403 (Forbidden), even if [[authentication was enabled|00001010040100]] and you did not provide a valid access token. -In this case, the resulting list might be quite short (some zettel will have [[public visibility|00001010070200]]) or the list might be empty. - -With this call, you cannot differentiate between an empty result list (e.g because your search did not found a zettel with the specified term) and an empty list because of missing authorization (e.g. an invalid access token). +=== Other output formats +If you want to get the list of metadata of all or some zettel in JSON format, use endpoint ''/q'' to [[query the list of zettel|00001012051400]]. === HTTP Status codes ; ''200'' : Retrieval was successful, the body contains an [[appropriate JSON object|00001012921000]]. ; ''400'' : Request was not valid. There are several reasons for this. Maybe the access bearer token was not valid. Index: docs/manual/00001012051400.zettel ================================================================== --- docs/manual/00001012051400.zettel +++ docs/manual/00001012051400.zettel @@ -2,94 +2,43 @@ title: API: Query the list of all zettel role: manual tags: #api #manual #zettelstore syntax: zmk created: 20220912111111 -modified: 20230116183844 +modified: 20220923105405 -The [[endpoint|00001012920000]] ''/z'' also allows you to filter the list of all zettel[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header] and optionally to provide some actions. +The [[endpoint|00001012920000]] ''/q'' allows to query the list of all zettel[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. A [[query|00001007700000]] is an optional [[search expression|00001007700000#search-expression]], together with an optional [[list of actions|00001007700000#action-list]] (described below). An empty search expression will select all zettel. An empty list of action, or no valid action, returns the list of all selected zettel metadata. Search expression and action list are separated by a vertical bar character (""''|''"", U+007C), and must be given with the query parameter ''q''. -The query parameter ""''q''"" allows you to specify [[query expressions|00001007700000]] for a full-text search of all zettel content and/or restricting the search according to specific metadata. - -It is allowed to specify this query parameter more than once. - -This parameter loosely resembles the search form of the [[web user interface|00001014000000]] or those of [[Zettelmarkup's Query Transclusion|00001007031140]]. - -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?q=title%3AAPI' -00001012921000 API: JSON structure of an access token -00001012920500 Formats available by the API -00001012920000 Endpoints used by the API -... -``` - -If you want to retrieve a JSON document: - -```sh -# curl 'http://127.0.0.1:23123/z?q=title%3AAPI&enc=json' -{"query":"title:API","human":"title HAS API","list":[{"id":"00001012921200","meta":{"back":"00001012051200 00001012051400 00001012053300 00001012053400 00001012053800 00001012053900 00001012054000","backward":"00001012051200 00001012051400 00001012053300 00001012053400 00001012053800 00001012053900 00001012054000","box-number":"1","created":"00010101000000","forward":"00001003000000 00001006020400 00001010000000 00001010040100 00001010040200 00001010070200 00001010070300","modified":"20220201171959","published":"20220201171959","role":"manual","syntax":"zmk","tags":"#api #manual #reference #zettelstore","title":"API: Encoding of Zettel Access Rights"},"rights":62},{"id":"00001012921000","meta":{"back":"00001012050600 00001012051200","backward":"00001012050200 00001012050400 00001012050600 00001012051200","box-number":"1","created":"00010101000000","forward":"00001012050200 00001012050400","published":"00010101000000","role":"manual","syntax":"zmk","tags":"#api #manual #reference #zettelstore","title":"API: JSON structure of an access token"},"rights":62}, ...] -``` - -The JSON object contains a key ''"list"'' where its value is a list of zettel JSON objects. -These zettel JSON objects themselves contains the keys ''"id"'' (value is a string containing the [[zettel identifier|00001006050000]]), ''"meta"'' (value as a JSON object), and ''"rights"'' (encodes the [[access rights|00001012921200]] for the given zettel). -The value of key ''"meta"'' effectively contains all metadata of the identified zettel, where metadata keys are encoded as JSON object keys and metadata values encoded as JSON strings. - -Additionally, the JSON object contains the keys ''"query"'' and ''"human"'' with a string value. -Both will contain a textual description of the underlying query if you select only some zettel with a [[query expression|00001007700000]]. -Without a selection, the values are the empty string. -''"query"'' returns the normalized query expression itself, while ''"human"'' is the normalized query expression to be read by humans. - - -An implicit precondition is that the zettel must contain the given metadata key. -For a metadata key like [[''title''|00001006020000#title]], which has a default value, this precondition should always be true. -But the situation is different for a key like [[''url''|00001006020000#url]]. -Both ``curl 'http://localhost:23123/z?q=url%3A'`` and ``curl 'http://localhost:23123/z?q=url%3A!'`` may result in an empty list. - - -As an example for a query action, to list all roles used in the Zettelstore, send a HTTP GET request to the endpoint ''/z?q=|role''. - -```sh -# curl 'http://127.0.0.1:23123/z?q=|role' -configuration 00001000000100 00000000090002 00000000090000 00000000040001 00000000025001 00000000020001 00000000000100 00000000000092 00000000000090 00000000000006 00000000000005 00000000000004 00000000000001 -manual 00001018000000 00001017000000 00001014000000 00001012921200 00001012921000 00001012920800 00001012920588 00001012920584 00001012920582 00001012920522 00001012920519 00001012920516 00001012920513 00001012920510 00001012920503 00001012920500 00001012920000 00001012080500 00001012080200 00001012080100 00001012070500 00001012054600 00001012054400 00001012054200 00001012054000 00001012053900 00001012053800 00001012053600 00001012053500 00001012053400 00001012053300 00001012053200 00001012051400 00001012051200 00001012050600 00001012050400 00001012050200 00001012000000 00001010090100 00001010070600 00001010070400 00001010070300 00001010070200 00001010040700 00001010040400 00001010040200 00001010040100 00001010000000 00001008050000 00001008010500 00001008010000 00001008000000 00001007990000 00001007906000 00001007903000 00001007900000 00001007800000 00001007790000 00001007780000 00001007706000 00001007705000 00001007702000 00001007700000 00001007050200 00001007050100 00001007050000 00001007040350 00001007040340 00001007040330 00001007040324 00001007040322 00001007040320 00001007040310 00001007040300 00001007040200 00001007040100 00001007040000 00001007031400 00001007031300 00001007031200 00001007031140 00001007031110 00001007031100 00001007031000 00001007030900 00001007030800 00001007030700 00001007030600 00001007030500 00001007030400 00001007030300 00001007030200 00001007030100 00001007030000 00001007020000 00001007010000 00001007000000 00001006055000 00001006050000 00001006036500 00001006036000 00001006035500 00001006035000 00001006034500 00001006034000 00001006033500 00001006033000 00001006032500 00001006032000 00001006031500 00001006031000 00001006030500 00001006030000 00001006020400 00001006020100 00001006020000 00001006010000 00001006000000 00001005090000 00001005000000 00001004101000 00001004100000 00001004059900 00001004059700 00001004051400 00001004051200 00001004051100 00001004051000 00001004050400 00001004050200 00001004050000 00001004020200 00001004020000 00001004011600 00001004011400 00001004011200 00001004010000 00001004000000 00001003600000 00001003315000 00001003310000 00001003305000 00001003300000 00001003000000 00001002000000 00001001000000 00001000000000 -zettel 00010000000000 00000000090001 -``` - -The result is a text file. -The first word, separated by a horizontal tab (U+0009) contains the role name. -The rest of the line consists of zettel identifier, where the corresponding zettel have this role. -Zettel identifier are separated by a space character (U+0020). - -Of course, this list can be returned as a JSON object: - -```sh -# curl 'http://127.0.0.1:23123/z?q=|role?enc=json' +For example, to list all roles used in the Zettelstore, send a HTTP GET request to the endpoint ''/q?q=|role''. +If successful, the output is a JSON object: + +```sh +# curl http://127.0.0.1:23123/q?q=|role {"map":{"configuration":["00000000090002","00000000090000", ... ,"00000000000001"],"manual":["00001014000000", ... ,"00001000000000"],"zettel":["00010000000000", ... ,"00001012070500","00000000090001"]}} ``` The JSON object only contains the key ''"map"'' with the value of another object. This second object contains all role names as keys and the list of identifier of those zettel with this specific role as a value. -Similar, to list all tags used in the Zettelstore, send a HTTP GET request to the endpoint ''/z?q=|tags''. +Similar, to list all tags used in the Zettelstore, send a HTTP GET request to the endpoint ''/q?q=|tags''. If successful, the output is a JSON object: ```sh -# curl 'http://127.0.0.1:23123/z?q=|tags&enc=json' +# curl http://127.0.0.1:23123/q?q=|tags {"map":{"#api":[:["00001012921000","00001012920800","00001012920522",...],"#authorization":["00001010040700","00001010040400",...],...,"#zettelstore":["00010000000000","00001014000000",...,"00001001000000"]}} ``` The JSON object only contains the key ''"map"'' with the value of another object. This second object contains all tags as keys and the list of identifier of those zettel with this tag as a value. -If you want only those tags that occur at least 100 times, use the endpoint ''/z?q=|MIN100+tags''. +If you want only those tags that occur at least 100 times, use the endpoint ''/q?q=|MIN100+tags''. You see from this that actions are separated by space characters. There are two types of actions: parameters and aggregates. The following actions are supported: ; ''MINn'' (parameter) @@ -102,10 +51,94 @@ : Emit an aggregate of the given metadata key. The key can be given in any letter case. Only the first aggregate action will be executed. +If no valid aggregate action is given, the metadata of all selected zettel are returned.[^For this reason, a HTTP GET to the endpoint ''/j'' is an alias for the endpoint ''/q''.] + +```sh +# curl http://127.0.0.1:23123/q +{"query":"","list":[{"id":"00001012051200","meta":{"title":"API: Renew an access token","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012050600","meta":{"title":"API: Provide an access token","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012050400","meta":{"title":"API: Renew an access token","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012050200","meta":{"title":"API: Authenticate a client","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62},{"id":"00001012000000","meta":{"title":"API","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual"},"rights":62}]} +``` + +The JSON object contains a key ''"list"'' where its value is a list of zettel JSON objects. +These zettel JSON objects themselves contains the keys ''"id"'' (value is a string containing the [[zettel identifier|00001006050000]]), ''"meta"'' (value as a JSON object), and ''"rights"'' (encodes the [[access rights|00001012921200]] for the given zettel). +The value of key ''"meta"'' effectively contains all metadata of the identified zettel, where metadata keys are encoded as JSON object keys and metadata values encoded as JSON strings. + +Additionally, the JSON object contains the keys ''"query"'' and ''"human"'' with a string value. +Both will contain a textual description of the underlying query if you select only some zettel with a [[query expression|00001007700000]]. +Without a selection, the values are the empty string. +''"query"'' returns the normalized query expression itself, while ''"human"'' is the normalized query expression to be read by humans. + +If you reformat the JSON output from the ''GET /q'' call, you'll see its structure better: + +```json +{ + "query": "", + "human": "", + "list": [ + { + "id": "00001012051200", + "meta": { + "title": "API: List for all zettel some data", + "tags": "#api #manual #zettelstore", + "syntax": "zmk", + "role": "manual" + }, + "rights":62 + }, + { + "id": "00001012050600", + "meta": { + "title": "API: Provide an access token", + "tags": "#api #manual #zettelstore", + "syntax": "zmk", + "role": "manual" + }, + "rights":62 + }, + { + "id": "00001012050400", + "meta": { + "title": "API: Renew an access token", + "tags": "#api #manual #zettelstore", + "syntax": "zmk", + "role": "manual" + }, + "rights":62 + }, + { + "id": "00001012050200", + "meta": { + "title": "API: Authenticate a client", + "tags": "#api #manual #zettelstore", + "syntax": "zmk", + "role": "manual" + }, + "rights":62 + }, + { + "id": "00001012000000", + "meta": { + "title": "API", + "tags": "#api #manual #zettelstore", + "syntax": "zmk", + "role": "manual" + }, + "rights":62 + } + ] +} +``` +In this special case, the metadata of each zettel just contains the four default keys ''title'', ''tags'', ''syntax'', and ''role''. + +=== Note +This request (and similar others) will always return a list of metadata, provided the request was syntactically correct. +There will never be a HTTP status code 403 (Forbidden), even if [[authentication was enabled|00001010040100]] and you did not provide a valid access token. +In this case, the resulting list might be quite short (some zettel will have [[public visibility|00001010070200]]) or the list might be empty. + +With this call, you cannot differentiate between an empty result list (e.g because your search did not found a zettel with the specified term) and an empty list because of missing authorization (e.g. an invalid access token). === HTTP Status codes ; ''200'' : Query was successful. ; ''204'' Index: docs/manual/00001012053200.zettel ================================================================== --- docs/manual/00001012053200.zettel +++ docs/manual/00001012053200.zettel @@ -1,32 +1,16 @@ id: 00001012053200 title: API: Create a new zettel role: manual tags: #api #manual #zettelstore syntax: zmk -created: 20210713150005 -modified: 20221219162225 - -A zettel is created by adding it to the [[list of zettel|00001012000000]]. -Therefore, the [[endpoint|00001012920000]] to create a new zettel is also ''/z'', but you must send the data of the new zettel via a HTTP POST request. - - -The zettel must be encoded in a [[plain|00001006000000]] format: first comes the [[metadata|00001006010000]] and the following content is separated by an empty line. -This is the same format as used by storing zettel within a [[directory box|00001006010000]]. - -``` -# curl -X POST --data $'title: Note\n\nImportant content.' http://127.0.0.1:23123/z -20210903211500 -``` - -The zettel identifier of the created zettel is returned. -In addition, the HTTP response header contains a key ''Location'' with a relative URL for the new zettel. -A client must prepend the HTTP protocol scheme, the host name, and (optional, but often needed) the post number to make it an absolute URL. - - -Alternatively, the body of the POST request may contain a JSON object that specifies metadata and content of the zettel to be created. -To do this, you must add the query parameter ''enc=json''. +modified: 20220628111320 + +A zettel is created by adding it to the [[list of zettel|00001012000000#zettel-lists]]. +Therefore, the [[endpoint|00001012920000]] to create a new zettel is also ''/j'', but you must send the data of the new zettel via a HTTP POST request. + +The body of the POST request must contain a JSON object that specifies metadata and content of the zettel to be created. The following keys of the JSON object are used: ; ''"meta"'' : References an embedded JSON object with only string values. The name/value pairs of this objects are interpreted as the metadata of the new zettel. Please consider the [[list of supported metadata keys|00001006020000]] (and their value types). @@ -44,22 +28,33 @@ Therefore, a body containing just ''{}'' is perfectly valid. The new zettel will have no content, and only an identifier as [[metadata|00001006020000]]: ``` -# curl -X POST --data '{}' 'http://127.0.0.1:23123/z?enc=json' +# curl -X POST --data '{}' http://127.0.0.1:23123/j {"id":"20210713161000"} ``` If creating the zettel was successful, the HTTP response will contain a JSON object with one key: ; ''"id"'' : Contains the [[zettel identifier|00001006050000]] of the created zettel for further usage. +In addition, the HTTP response header contains a key ''Location'' with a relative URL for the new zettel. +A client must prepend the HTTP protocol scheme, the host name, and (optional, but often needed) the post number to make it an absolute URL. + As an example, a zettel with title ""Note"" and content ""Important content."" can be created by issuing: ``` -# curl -X POST --data '{"meta":{"title":"Note"},"content":"Important content."}' 'http://127.0.0.1:23123/z?enc=json' +# curl -X POST --data '{"meta":{"title":"Note"},"content":"Important content."}' http://127.0.0.1:23123/j {"id":"20210713163100"} ``` + +[!plain]Alternatively, you can use the [[endpoint|00001012920000]] ''/z'' to create a new zettel. +In this case, the zettel must be encoded in a [[plain|00001006000000]] format: first comes the [[metadata|00001006010000]] and the following content is separated by an empty line. +This is the same format as used by storing zettel within a [[directory box|00001006010000]]. +``` +# curl -X POST --data $'title: Note\n\nImportant content.' http://127.0.0.1:23123/z +20210903211500 +``` === HTTP Status codes ; ''201'' : Zettel creation was successful, the body contains its [[zettel identifier|00001006050000]] (JSON object or plain text). ; ''400'' Index: docs/manual/00001012053300.zettel ================================================================== --- docs/manual/00001012053300.zettel +++ docs/manual/00001012053300.zettel @@ -2,71 +2,39 @@ title: API: Retrieve metadata and content of an existing zettel role: manual tags: #api #manual #zettelstore syntax: zmk created: 20211004093206 -modified: 20221219160613 - -The [[endpoint|00001012920000]] to work with metadata and content of a specific zettel is ''/z/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. - -For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint ''/z/00001012053300''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. - -````sh -# curl 'http://127.0.0.1:23123/z/00001012053300' -The [[endpoint|00001012920000]] to work with metadata and content of a specific zettel is ''/z/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. - -For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint ''/z/00001012053300''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. - -```sh -... -```` - -Optionally, you may provide which parts of the zettel you are requesting. -In this case, add an additional query parameter ''part=PART''. -Valid values for [[''PART''|00001012920800]] are ""zettel"", ""[[meta|00001012053400]]"", and ""content"" (the default value). - - -````sh -# curl 'http://127.0.0.1:23123/z/00001012053300?part=zettel' -title: API: Retrieve metadata and content of an existing zettel -role: manual -tags: #api #manual #zettelstore -syntax: zmk - -The [[endpoint|00001012920000]] to work with metadata and content of a specific zettel is ''/z/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. - -For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint -... -```` - -=== JSON output - -Alternatively, you may retrieve the zettel as a JSON object by providinv the query parameter ''enc=json'': -```sh -# curl 'http://127.0.0.1:23123/z/00001012053300?enc=json&part=zettel' -{"id":"00001012053300","meta":{"back":"00001012000000 00001012054400","backward":"00001012000000 00001012054400 00001012920000","box-number":"1","created":"20211004093206","forward":"00001006020000 00001006050000 00001010040100 00001012050200 00001012053400 00001012920000 00001012920800 00001012921200","modified":"20221219160211","published":"20221219160211","role":"manual","syntax":"zmk","tags":"#api #manual #zettelstore","title":"API: Retrieve metadata and content of an existing zettel"},"encoding":"","content":"The [[endpoint|00001012920000]] to work with metadata and content of a specific zettel is ''/z/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]].\n\nFor example, ... +modified: 20220908162927 + +The [[endpoint|00001012920000]] to work with metadata and content of a specific zettel is ''/j/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. + +For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint ''/j/00001012053300''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. +If successful, the output is a JSON object: +```sh +# curl http://127.0.0.1:23123/j/00001012053300 +{"id":"00001012053300","meta":{"title":"API: Retrieve data for an existing zettel","tags":"#api #manual #zettelstore","syntax":"zmk","role":"manual","copyright":"(c) 2020 by Detlef Stern ","lang":"en","license":"CC BY-SA 4.0"},"content":"The endpoint to work with a specific zettel is ''/j/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000}}.\n\nFor example, ... ``` Pretty-printed, this results in: ``` { "id": "00001012053300", "meta": { - "back": "00001012000000 00001012054400", - "backward": "00001012000000 00001012054400 00001012920000", + "back": "00001012000000 00001012053200 00001012054400", + "backward": "00001012000000 00001012053200 00001012054400 00001012920000", "box-number": "1", - "created": "20211004093206", - "forward": "00001006020000 00001006050000 00001010040100 00001012050200 00001012053400 00001012920000 00001012920800 00001012921200", - "modified": "20221219160211", - "published": "20221219160211", + "forward": "00001010040100 00001012050200 00001012920000 00001012920800", + "modified": "20210726190012", + "published": "20210726190012", "role": "manual", "syntax": "zmk", "tags": "#api #manual #zettelstore", "title": "API: Retrieve metadata and content of an existing zettel" }, "encoding": "", - "content": "The [[endpoint|00001012920000]] to work with metadata and content of a specific zettel is ''/z/{ID}'', where ''{ID}'' (...) + "content": "The [[endpoint|00001012920000]] to work with metadata and content of a specific zettel is ''/j/{ID}'', where ''{ID}'' (...) "rights": 62 } ``` The following keys of the JSON object are used: @@ -83,10 +51,40 @@ ; ''"content"'' : Is a string value that contains the content of the zettel to be created. Typically, text content is not encoded, and binary content is encoded via Base64. ; ''"rights"'' : An integer number that describes the [[access rights|00001012921200]] for the zettel. + +=== Plain zettel +[!plain]Additionally, you can retrieve the plain zettel, without using JSON. +Just change the [[endpoint|00001012920000]] to ''/z/{ID}'' +Optionally, you may provide which parts of the zettel you are requesting. +In this case, add an additional query parameter ''part=PART''. +Valid values for [[''PART''|00001012920800]] are ""zettel"", ""[[meta|00001012053400]]"", and ""content"" (the default value). + +````sh +# curl 'http://127.0.0.1:23123/z/00001012053300' +The [[endpoint|00001012920000]] to work with metadata and content of a specific zettel is ''/j/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. + +For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint ''/j/00001012053300''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. +If successful, the output is a JSON object: +```sh +... +```` + +````sh +# curl 'http://127.0.0.1:23123/z/00001012053300?part=zettel' +title: API: Retrieve metadata and content of an existing zettel +role: manual +tags: #api #manual #zettelstore +syntax: zmk + +The [[endpoint|00001012920000]] to work with metadata and content of a specific zettel is ''/j/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. + +For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint +... +```` === HTTP Status codes ; ''200'' : Retrieval was successful, the body contains an appropriate JSON object / plain zettel data. ; ''204'' Index: docs/manual/00001012053400.zettel ================================================================== --- docs/manual/00001012053400.zettel +++ docs/manual/00001012053400.zettel @@ -2,42 +2,31 @@ title: API: Retrieve metadata of an existing zettel role: manual tags: #api #manual #zettelstore syntax: zmk created: 20210726174524 -modified: 20221219161030 - -The [[endpoint|00001012920000]] to work with metadata of a specific zettel is ''/z/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]][^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. - -To retrieve the plain metadata of a zettel, use the query parameter ''part=meta'' - -````sh -# curl 'http://127.0.0.1:23123/z/00001012053400?part=meta' -title: API: Retrieve metadata of an existing zettel -role: manual -tags: #api #manual #zettelstore -syntax: zmk -```` - -To return a JSON object, use also the query parameter ''enc=json''. - -```sh -# curl 'http://127.0.0.1:23123/z/00001012053400?part=meta&enc=json' -{"meta":{"back":"00001012000000 00001012053300","backward":"00001012000000 00001012053300 00001012920000","box-number":"1","created":"20210726174524","forward":"00001006020000 00001006050000 00001010040100 00001012050200 00001012920000 00001012921200","modified":"20220917175233","published":"20220917175233","role":"manual","syntax":"zmk","tags":"#api #manual #zettelstore","title":"API: Retrieve metadata of an existing zettel"},"rights":62} +modified: 20220917175233 + +The [[endpoint|00001012920000]] to work with metadata of a specific zettel is ''/m/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. + +For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint ''/j/00001012053400''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. +If successful, the output is a JSON object: +```sh +# curl http://127.0.0.1:23123/m/00001012053400 +{"meta":{"back":"00001012000000 00001012053300","backward":"00001012000000 00001012053300 00001012920000","box-number":"1","forward":"00001010040100 00001012050200 00001012920000 00001012920800","modified":"20211004111240","published":"20211004111240","role":"manual","syntax":"zmk","tags":"#api #manual #zettelstore","title":"API: Retrieve metadata of an existing zettel"},"rights":62} ``` Pretty-printed, this results in: ``` { "meta": { "back": "00001012000000 00001012053300", "backward": "00001012000000 00001012053300 00001012920000", "box-number": "1", - "created": "20210726174524", - "forward": "00001006020000 00001006050000 00001010040100 00001012050200 00001012920000 00001012921200", - "modified": "20220917175233", - "published": "20220917175233", + "forward": "00001010040100 00001012050200 00001012920000 00001012920800", + "modified": "20211004111240", + "published": "20211004111240", "role": "manual", "syntax": "zmk", "tags": "#api #manual #zettelstore", "title": "API: Retrieve metadata of an existing zettel" }, @@ -50,10 +39,20 @@ The name/value pairs of this objects are interpreted as the metadata of the new zettel. Please consider the [[list of supported metadata keys|00001006020000]] (and their value types). ; ''"rights"'' : An integer number that describes the [[access rights|00001012921200]] for the zettel. +[!plain]Additionally, you can retrieve the plain metadata of a zettel, without using JSON. +Just change the [[endpoint|00001012920000]] to ''/z/{ID}?part=meta'' + +````sh +# curl 'http://127.0.0.1:23123/z/00001012053400?part=meta' +title: API: Retrieve metadata of an existing zettel +role: manual +tags: #api #manual #zettelstore +syntax: zmk +```` === HTTP Status codes ; ''200'' : Retrieval was successful, the body contains an appropriate JSON object. ; ''400'' Index: docs/manual/00001012053500.zettel ================================================================== --- docs/manual/00001012053500.zettel +++ docs/manual/00001012053500.zettel @@ -2,51 +2,62 @@ title: API: Retrieve evaluated metadata and content of an existing zettel in various encodings role: manual tags: #api #manual #zettelstore syntax: zmk created: 20210726174524 -modified: 20230109105303 +modified: 20221107183404 -The [[endpoint|00001012920000]] to work with evaluated metadata and content of a specific zettel is ''/z/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. +The [[endpoint|00001012920000]] to work with evaluated metadata and content of a specific zettel is ''/v/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. -For example, to retrieve some evaluated data about this zettel you are currently viewing in [[Sexpr encoding|00001012920516]], just send a HTTP GET request to the endpoint ''/z/00001012053500''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header] with the query parameter ''enc=sexpr''. +For example, to retrieve some evaluated data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint ''/v/00001012053500''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. If successful, the output is a JSON object: ```sh -# curl 'http://127.0.0.1:23123/z/00001012053500?enc=sexpr' -((PARA (TEXT "The") (SPACE) (LINK-ZETTEL () "00001012920000" (TEXT "endpoint")) (SPACE) (TEXT "to") (SPACE) (TEXT "work") (SPACE) (TEXT "with") (SPACE) (TEXT "evaluated") (SPACE) (TEXT "metadata") (SPACE) (TEXT "and") (SPACE) (TEXT "content") (SPACE) (TEXT "of") (SPACE) (TEXT "a") (SPACE) (TEXT "specific") (SPACE) (TEXT "zettel") (SPACE) (TEXT "is") (SPACE) (LITERAL-INPUT () "/z/{ID}") (TEXT ",") (SPACE) (TEXT "where") (SPACE) (LITERAL-INPUT () "{ID}") ... +# curl http://127.0.0.1:23123/v/00001012053500 +{"meta":{"title":[{"t":"Text","s":"API:"},{"t":"Space"},{"t":"Text","s":"Retrieve"},{"t":"Space"},{"t":"Text","s":"evaluated"},{"t":"Space"},{"t":"Text","s":"metadata"},{"t":"Space"},{"t":"Text","s":"and"},{"t":"Space"},{"t":"Text","s":"content"},{"t":"Space"},{"t":"Text","s":"of"},{"t":"Space"},{"t":"Text","s":"an"},{"t":"Space"},{"t":"Text","s":"existing"},{"t":"Space"},{"t":"Text","s":"zettel"},{"t":"Space"},{"t":"Text","s":"in"},{"t":"Space"}, ... ``` -To select another encoding, you must provide the query parameter ''enc=ENCODING''. +To select another encoding, you can provide a query parameter ''enc=ENCODING''. +The default value for [[''ENCODING''|00001012920500]] is ""[[zjson|00001012920503]]"". Others are ""[[html|00001012920510]]"", ""[[text|00001012920519]]"", and some [[more|00001012920500]]. -In addition, you may provide a query parameter ''part=PART'' to select the relevant [[part|00001012920800]] of a zettel. ```sh -# curl 'http://127.0.0.1:23123/z/00001012053500?enc=html&part=zettel' - +# curl 'http://127.0.0.1:23123/v/00001012053500?enc=html' + + API: Retrieve evaluated metadata and content of an existing zettel in various encodings - - + - - + + - - - - - - - - + + + -

    API: Retrieve evaluated metadata and content of an existing zettel in various encodings

    -

    The endpoint to work with evaluated metadata and content of a specific zettel is /z/{ID}, +

    The endpoint to work with evaluated metadata and content of a specific zettel is /v/{ID}, where {ID} is a placeholder for the zettel identifier.

    ... ``` + +You also can use the query parameter ''part=PART'' to specify which [[parts|00001012920800]] of a zettel must be encoded. +In this case, its default value is ''content''. +```sh +# curl 'http://127.0.0.1:23123/v/00001012053500?enc=html&part=meta' + + + + + + + + + + + +``` === HTTP Status codes ; ''200'' : Retrieval was successful, the body contains an appropriate JSON object. ; ''400'' Index: docs/manual/00001012053600.zettel ================================================================== --- docs/manual/00001012053600.zettel +++ docs/manual/00001012053600.zettel @@ -2,22 +2,22 @@ title: API: Retrieve parsed metadata and content of an existing zettel in various encodings role: manual tags: #api #manual #zettelstore syntax: zmk created: 20210126175322 -modified: 20230109105034 +modified: 20220908163514 -The [[endpoint|00001012920000]] to work with parsed metadata and content of a specific zettel is ''/z/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. +The [[endpoint|00001012920000]] to work with parsed metadata and content of a specific zettel is ''/p/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. A __parsed__ zettel is basically an [[unevaluated|00001012053500]] zettel: the zettel is read and analyzed, but its content is not __evaluated__. By using this endpoint, you are able to retrieve the structure of a zettel before it is evaluated. -For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint ''/z/00001012053600''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header] with the query parameter ''parseonly'' (and other appropriate query parameter). -For example: +For example, to retrieve some data about this zettel you are currently viewing, just send a HTTP GET request to the endpoint ''/v/00001012053600''[^If [[authentication is enabled|00001010040100]], you must include the a valid [[access token|00001012050200]] in the ''Authorization'' header]. +If successful, the output is a JSON object: ```sh -# curl 'http://127.0.0.1:23123/z/00001012053600?enc=sexpr&parseonly' -((PARA (TEXT "The") (SPACE) (LINK-ZETTEL () "00001012920000" (TEXT "endpoint")) (SPACE) (TEXT "to") (SPACE) (TEXT "work") (SPACE) (TEXT "with") (SPACE) ... +# curl http://127.0.0.1:23123/p/00001012053600 +[{"t":"Para","i":[{"t":"Text","s":"The"},{"t":"Space"},{"t":"Link","q":"zettel","s":"00001012920000","i":[{"t":"Text","s":"endpoint"}]},{"t":"Space"},{"t":"Text","s":"to"},{"t":"Space"},{"t":"Text","s":"work"},{"t":"Space"},{"t":"Text","s":"with"},{"t":"Space"}, ... ``` Similar to [[retrieving an encoded zettel|00001012053500]], you can specify an [[encoding|00001012920500]] and state which [[part|00001012920800]] of a zettel you are interested in. The same default values applies to this endpoint. Index: docs/manual/00001012054200.zettel ================================================================== --- docs/manual/00001012054200.zettel +++ docs/manual/00001012054200.zettel @@ -1,36 +1,33 @@ id: 00001012054200 title: API: Update a zettel role: manual tags: #api #manual #zettelstore syntax: zmk -created: 20210713150005 -modified: 20221219155029 +modified: 20211124180943 Updating metadata and content of a zettel is technically quite similar to [[creating a new zettel|00001012053200]]. In both cases you must provide the data for the new or updated zettel in the body of the HTTP request. One difference is the endpoint. -The [[endpoint|00001012920000]] to update a zettel is ''/z/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. -You must send a HTTP PUT request to that endpoint. - -The zettel must be encoded in a [[plain|00001006000000]] format: first comes the [[metadata|00001006010000]] and the following content is separated by an empty line. -This is the same format as used by storing zettel within a [[directory box|00001006010000]]. +The [[endpoint|00001012920000]] to update a zettel is ''/j/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. +You must send a HTTP PUT request to that endpoint: ``` -# curl -X POST --data 'title: Updated Note\n\nUpdated content.' http://127.0.0.1:23123/z/00001012054200 -``` - -Alternatively, you can use the JSON encoding by using the query parameter ''enc=json''. - -``` -# curl -X PUT --data '{}' 'http://127.0.0.1:23123/z/00001012054200?enc=json' +# curl -X PUT --data '{}' http://127.0.0.1:23123/j/00001012054200 ``` This will put some empty content and metadata to the zettel you are currently reading. As usual, some metadata will be calculated if it is empty. The body of the HTTP response is empty, if the request was successful. + +[!plain]Alternatively, you can use the [[endpoint|00001012920000]] ''/z/{ID}'' to update a zettel. +In this case, the zettel must be encoded in a [[plain|00001006000000]] format: first comes the [[metadata|00001006010000]] and the following content is separated by an empty line. +This is the same format as used by storing zettel within a [[directory box|00001006010000]]. +``` +# curl -X POST --data $'title: Updated Note\n\nUpdated content.' http://127.0.0.1:23123/z/00001012054200 +``` === HTTP Status codes ; ''204'' : Update was successful, there is no body in the response. ; ''400'' Index: docs/manual/00001012054400.zettel ================================================================== --- docs/manual/00001012054400.zettel +++ docs/manual/00001012054400.zettel @@ -1,30 +1,32 @@ id: 00001012054400 title: API: Rename a zettel role: manual tags: #api #manual #zettelstore syntax: zmk -created: 20210713150005 -modified: 20221219154659 +modified: 20211124181324 Renaming a zettel is effectively just specifying a new identifier for the zettel. Since more than one [[box|00001004011200]] might contain a zettel with the old identifier, the rename operation must success in every relevant box to be overall successful. If the rename operation fails in one box, Zettelstore tries to rollback previous successful operations. As a consequence, you cannot rename a zettel when its identifier is used in a read-only box. This applies to all [[predefined zettel|00001005090000]], for example. -The [[endpoint|00001012920000]] to rename a zettel is ''/z/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. +The [[endpoint|00001012920000]] to rename a zettel is ''/j/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. You must send a HTTP MOVE request to this endpoint, and you must specify the new zettel identifier as an URL, placed under the HTTP request header key ''Destination''. ``` -# curl -X MOVE -H "Destination: 10000000000001" http://127.0.0.1:23123/z/00001000000000 +# curl -X MOVE -H "Destination: 10000000000001" http://127.0.0.1:23123/j/00001000000000 ``` Only the last 14 characters of the value of ''Destination'' are taken into account and those must form an unused [[zettel identifier|00001006050000]]. If the value contains less than 14 characters that do not form an unused zettel identifier, the response will contain a HTTP status code ''400''. All other characters, besides those 14 digits, are effectively ignored. However, the value should form a valid URL that could be used later to [[read the content|00001012053300]] of the freshly renamed zettel. + +[!plain]Alternatively, you can also use the [[endpoint|00001012920000]] ''/z/{ID}''. +Both endpoints behave identical. === HTTP Status codes ; ''204'' : Rename was successful, there is no body in the response. ; ''400'' Index: docs/manual/00001012054600.zettel ================================================================== --- docs/manual/00001012054600.zettel +++ docs/manual/00001012054600.zettel @@ -1,22 +1,24 @@ id: 00001012054600 title: API: Delete a zettel role: manual tags: #api #manual #zettelstore syntax: zmk -created: 20210713150005 -modified: 20221219154608 +modified: 20211124181041 Deleting a zettel within the Zettelstore is executed on the first [[box|00001004011200]] that contains that zettel. Zettel with the same identifier, but in subsequent boxes remain. If the first box containing the zettel is read-only, deleting that zettel will fail, as well for a Zettelstore in [[read-only mode|00001004010000#read-only-mode]] or if [[authentication is enabled|00001010040100]] and the user has no [[access right|00001010070600]] to do so. -The [[endpoint|00001012920000]] to delete a zettel is ''/z/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. +The [[endpoint|00001012920000]] to delete a zettel is ''/j/{ID}'', where ''{ID}'' is a placeholder for the [[zettel identifier|00001006050000]]. You must send a HTTP DELETE request to this endpoint: ``` -# curl -X DELETE http://127.0.0.1:23123/z/00001000000000 +# curl -X DELETE http://127.0.0.1:23123/j/00001000000000 ``` + +[!plain]Alternatively, you can also use the [[endpoint|00001012920000]] ''/z/{ID}''. +Both endpoints behave identical. === HTTP Status codes ; ''204'' : Delete was successful, there is no body in the response. ; ''403'' Index: docs/manual/00001012920000.zettel ================================================================== --- docs/manual/00001012920000.zettel +++ docs/manual/00001012920000.zettel @@ -2,11 +2,11 @@ title: Endpoints used by the API role: manual tags: #api #manual #reference #zettelstore syntax: zmk created: 20210126175322 -modified: 20221219162335 +modified: 20220923101703 All API endpoints conform to the pattern ''[PREFIX]LETTER[/ZETTEL-ID]'', where: ; ''PREFIX'' : is the URL prefix (default: ""/""), configured via the ''url-prefix'' [[startup configuration|00001004010000]], ; ''LETTER'' @@ -17,18 +17,26 @@ The following letters are currently in use: |= Letter:| Without zettel identifier | With [[zettel identifier|00001006050000]] | Mnemonic | ''a'' | POST: [[client authentication|00001012050200]] | | **A**uthenticate | | PUT: [[renew access token|00001012050400]] | +| ''j'' | GET: [[query zettel list|00001012051400]] (alias of ''/q'') | GET: [[retrieve zettel AS JSON|00001012053300]] | **J**SON +| | POST: [[create new zettel|00001012053200]] | PUT: [[update a zettel|00001012054200]] +| | | DELETE: [[delete the zettel|00001012054600]] +| | | MOVE: [[rename the zettel|00001012054400]] +| ''m'' | | GET: [[retrieve metadata|00001012053400]] | **M**etadata | ''o'' | | GET: [[list zettel order|00001012054000]] | **O**rder +| ''p'' | | GET: [[retrieve parsed zettel|00001012053600]]| **P**arsed +| ''q'' | GET: [[query zettel list|00001012051400]] | | **Q**uery | ''u'' | | GET [[unlinked references|00001012053900]] | **U**nlinked +| ''v'' | | GET: [[retrieve evaluated zettel|00001012053500]] | E**v**aluated | ''x'' | GET: [[retrieve administrative data|00001012070500]] | GET: [[list zettel context|00001012053800]] | Conte**x**t | | POST: [[execute command|00001012080100]] -| ''z'' | GET: [[list zettel|00001012051200]] | GET: [[retrieve zettel|00001012053300]] | **Z**ettel -| | POST: [[create new zettel|00001012053200]] | PUT: [[update a zettel|00001012054200]] -| | | DELETE: [[delete zettel|00001012054600]] -| | | MOVE: [[rename zettel|00001012054400]] +| ''z'' | GET: [[list zettel|00001012051200#plain]] | GET: [[retrieve zettel|00001012053300#plain]] | **Z**ettel +| | POST: [[create new zettel|00001012053200#plain]] | PUT: [[update a zettel|00001012054200#plain]] +| | | DELETE: [[delete zettel|00001012054600#plain]] +| | | MOVE: [[rename zettel|00001012054400#plain]] The full URL will contain either the ""http"" oder ""https"" scheme, a host name, and an optional port number. The API examples will assume the ""http"" schema, the local host ""127.0.0.1"", the default port ""23123"", and the default empty ''PREFIX'' ""/"". Therefore, all URLs in the API documentation will begin with ""http://127.0.0.1:23123/"". Index: docs/manual/00001012920500.zettel ================================================================== --- docs/manual/00001012920500.zettel +++ docs/manual/00001012920500.zettel @@ -2,15 +2,15 @@ title: Encodings available via the [[API|00001012000000]] role: manual tags: #api #manual #reference #zettelstore syntax: zmk created: 20210126175322 -modified: 20230109104839 +modified: 20221107182839 A zettel representation can be encoded in various formats for further processing. * [[html|00001012920510]] * [[md|00001012920513]] * [[sexpr|00001012920516]] * [[text|00001012920519]] -* [[zjson|00001012920503]] (will be deprecated in v0.11) +* [[zjson|00001012920503]] (default) * [[zmk|00001012920522]] Index: docs/manual/00001012920503.zettel ================================================================== --- docs/manual/00001012920503.zettel +++ docs/manual/00001012920503.zettel @@ -2,22 +2,20 @@ title: ZJSON Encoding role: manual tags: #api #manual #reference #zettelstore syntax: zmk created: 20210126175322 -modified: 20230109104722 +modified: 20220908163450 -**Note**: ZJSON encoding will be deprecated in v0.11 ---- A zettel representation that allows to process the syntactic structure of a zettel. -It is a JSON-based encoding format, but different to the structures returned by using the plain [[endpoint|00001012920000]] ''/z/{ID}''. +It is a JSON-based encoding format, but different to the structures returned by [[endpoint|00001012920000]] ''/j/{ID}''. For an example, take a look at the ZJSON encoding of this page, which is available via the ""Info"" sub-page of this zettel: -* [[//z/00001012920503?enc=zjson&part=zettel]], -* [[//z/00001012920503?enc=zjson&part=meta]], -* [[//z/00001012920503?enc=zjson&part=content]]. +* [[//v/00001012920503?enc=zjson&part=zettel]], +* [[//v/00001012920503?enc=zjson&part=meta]], +* [[//v/00001012920503?enc=zjson&part=content]]. If transferred via HTTP, the content type will be ''application/json''. A full zettel encoding results in a JSON object with two keys: ''"meta"'' and ''"content"''. Both values are the same as if you have requested just the appropriate [[part|00001012920800]]. Index: docs/manual/00001012920516.zettel ================================================================== --- docs/manual/00001012920516.zettel +++ docs/manual/00001012920516.zettel @@ -2,22 +2,22 @@ title: Sexpr Encoding role: manual tags: #api #manual #reference #zettelstore syntax: zmk created: 20220422181104 -modified: 20230109104812 +modified: 20220908163427 A zettel representation that is a [[s-expression|https://en.wikipedia.org/wiki/S-expression]] (also known as symbolic expression). -It is an alternative to the [[ZJSON encoding|00001012920503]][^ZJSON will be deprecated in v0.11]. +It is an alternative to the [[ZJSON encoding|00001012920503]]. Both encodings are (relatively) easy to parse and contain all relevant information of a zettel, metadata and content. For example, take a look at the Sexpr encoding of this page, which is available via the ""Info"" sub-page of this zettel: -* [[//z/00001012920516?enc=sexpr&part=zettel]], -* [[//z/00001012920516?enc=sexpr&part=meta]], -* [[//z/00001012920516?enc=sexpr&part=content]]. +* [[//v/00001012920516?enc=sexpr&part=zettel]], +* [[//v/00001012920516?enc=sexpr&part=meta]], +* [[//v/00001012920516?enc=sexpr&part=content]]. If transferred via HTTP, the content type will be ''text/plain''. === Syntax of s-expressions There are only two types of elements: atoms and lists. Index: docs/manual/00001012920582.zettel ================================================================== --- docs/manual/00001012920582.zettel +++ docs/manual/00001012920582.zettel @@ -1,16 +1,14 @@ id: 00001012920582 title: ZJSON Encoding: List of Valid Metadata Value Objects Names role: manual tags: #api #manual #reference #zettelstore syntax: zmk -modified: 20230109104713 +modified: 20220223184324 -**Note**: ZJSON encoding will be deprecated in v0.11 ---- Every Metadata value element is mapped to a JSON object with some well defined names / keys. |=Name | JSON Value | Meaning | ''"\"'' | string | The type of the Zettelmarkup element. | ''"i"'' | array | A sequence of [[inline-structured|00001007040000]] elements. | ''"s"'' | string | The first / major string value of an element. | ''"y"'' | array | A set of string values. Index: docs/manual/00001012920584.zettel ================================================================== --- docs/manual/00001012920584.zettel +++ docs/manual/00001012920584.zettel @@ -1,14 +1,12 @@ id: 00001012920584 title: ZJSON Encoding: Mapping of Metadata Key Types to Object Names role: manual tags: #api #manual #reference #zettelstore syntax: zmk -modified: 20230109104703 +modified: 20220304114135 -**Note**: ZJSON encoding will be deprecated in v0.11 ---- Every [[Metadata key|00001006030000]] is mapped to an [[object name|00001012920582]] where its value is encoded. |=Type | JSON Object Name | Remark | [[Credential|00001006031000]] | ''"s"'' | A string with the decrypted credential. | [[EString|00001006031500]] | ''"s"'' | A possibly empty string. Index: docs/manual/00001012920588.zettel ================================================================== --- docs/manual/00001012920588.zettel +++ docs/manual/00001012920588.zettel @@ -1,14 +1,11 @@ id: 00001012920588 title: ZJSON Encoding: List of Valid Zettelmarkup Element Objects Names role: manual tags: #api #manual #reference #zettelstore syntax: zmk -modified: 20230109104648 - -**Note**: ZJSON encoding will be deprecated in v0.11 ---- +modified: 20220301102447 Every [[Zettelmarkup|00001007000000]] element is mapped to a JSON object with some well defined names / keys. |=Name | JSON Value | Meaning | ''"\"'' | string | The type of the Zettelmarkup element. Index: domain/meta/meta.go ================================================================== --- domain/meta/meta.go +++ domain/meta/meta.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -151,11 +151,10 @@ registerKey(api.KeyLicense, TypeEmpty, usageUser, "") registerKey(api.KeyModified, TypeTimestamp, usageComputed, "") registerKey(api.KeyPrecursor, TypeIDSet, usageUser, api.KeyFolge) registerKey(api.KeyPredecessor, TypeID, usageUser, api.KeySuccessors) registerKey(api.KeyPublished, TypeTimestamp, usageProperty, "") - registerKey(api.KeyQuery, TypeEmpty, usageUser, "") registerKey(api.KeyReadOnly, TypeWord, usageUser, "") registerKey(api.KeySummary, TypeZettelmarkup, usageUser, "") registerKey(api.KeyURL, TypeURL, usageUser, "") registerKey(api.KeyUselessFiles, TypeString, usageProperty, "") registerKey(api.KeyUserID, TypeWord, usageUser, "") Index: encoder/encoder.go ================================================================== --- encoder/encoder.go +++ encoder/encoder.go @@ -71,5 +71,13 @@ for enc := range registry { result = append(result, enc) } return result } + +// GetDefaultEncoding returns the encoding that should be used as default. +func GetDefaultEncoding() api.EncodingEnum { + if _, ok := registry[api.EncoderZJSON]; ok { + return api.EncoderZJSON + } + panic("No ZJSON encoding registered") +} Index: encoder/encoder_blob_test.go ================================================================== --- encoder/encoder_blob_test.go +++ encoder/encoder_blob_test.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2021-2023 Detlef Stern +// Copyright (c) 2021-2022 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 @@ -38,15 +38,15 @@ 0x55, 0x00, 0x00, 0x00, 0x0a, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x63, 0x62, 0x00, 0x00, 0x00, 0x06, 0x00, 0x03, 0x36, 0x37, 0x7c, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82, }, expect: expectMap{ - encoderZJSON: `[{"":"BLOB","q":[{"":"Text","s":"PNG"}],"s":"png","o":"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg=="}]`, - encoderHTML: `

    PNG

    `, - encoderSexpr: `((BLOB ((TEXT "PNG")) "png" "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg=="))`, + encoderZJSON: `[{"":"BLOB","q":"PNG","s":"png","o":"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg=="}]`, + encoderHTML: `

    `, + encoderSexpr: `((BLOB "PNG" "png" "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg=="))`, encoderText: "", - encoderZmk: `%% Unable to display BLOB with description 'PNG' and syntax 'png'.`, + encoderZmk: `%% Unable to display BLOB with title 'PNG' and syntax 'png'.`, }, }, } func TestBlob(t *testing.T) { Index: encoder/encoder_block_test.go ================================================================== --- encoder/encoder_block_test.go +++ encoder/encoder_block_test.go @@ -323,21 +323,10 @@ encoderZJSON: `[{"":"Transclude","a":{"width":"100px"},"q":"external","s":"http://example.com/image"}]`, encoderHTML: `

    `, encoderMD: "", encoderSexpr: `((TRANSCLUDE (("width" "100px")) (EXTERNAL "http://example.com/image")))`, encoderText: "", - encoderZmk: useZmk, - }, - }, - { - descr: "A paragraph with a inline comment only should be empty in HTML", - zmk: `%% Comment`, - expect: expectMap{ - encoderZJSON: `[{"":"Para","i":[{"":"Comment","s":"Comment"}]}]`, - encoderHTML: ``, - encoderSexpr: `((PARA (LITERAL-COMMENT () "Comment")))`, - encoderText: "", encoderZmk: useZmk, }, }, { descr: "", Index: encoder/encoder_inline_test.go ================================================================== --- encoder/encoder_inline_test.go +++ encoder/encoder_inline_test.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2021-2023 Detlef Stern +// Copyright (c) 2021-2022 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 @@ -506,11 +506,11 @@ { descr: "Dummy Embed", zmk: `{{abc}}`, expect: expectMap{ encoderZJSON: `[{"":"Embed","s":"abc"}]`, - encoderHTML: `alternate description missing`, + encoderHTML: ``, encoderMD: "![abc](abc)", encoderSexpr: `((EMBED () (EXTERNAL "abc") ""))`, encoderText: ``, encoderZmk: useZmk, }, Index: encoder/htmlenc/htmlenc.go ================================================================== --- encoder/htmlenc/htmlenc.go +++ encoder/htmlenc/htmlenc.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2022-2023 Detlef Stern +// Copyright (c) 2022 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 @@ -55,18 +55,18 @@ io.WriteString(w, "\n\n") env := html.NewEncEnvironment(w, 1) if hasTitle { if isTitle := evalMeta(plainTitle); len(isTitle) > 0 { io.WriteString(w, "

    ") - if err := acceptInlines(env, &isTitle); err != nil { - return 0, err + if l, err := acceptInlines(env, &isTitle); err != nil { + return l, err } io.WriteString(w, "

    \n") } } - err := acceptBlocks(env, &zn.Ast) + _, err := acceptBlocks(env, &zn.Ast) if err == nil { // env.WriteEndnotes() io.WriteString(w, "\n") } return 0, err @@ -83,11 +83,11 @@ } // WriteBlocks encodes a block slice. func (*Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { env := html.NewEncEnvironment(w, 1) - err := acceptBlocks(env, bs) + _, err := acceptBlocks(env, bs) if err == nil { env.WriteEndnotes() err = env.GetError() } return 0, err @@ -94,11 +94,11 @@ } // WriteInlines writes an inline slice to the writer func (*Encoder) WriteInlines(w io.Writer, is *ast.InlineSlice) (int, error) { env := html.NewEncEnvironment(w, 1) - return 0, acceptInlines(env, is) + return acceptInlines(env, is) } func acceptMeta(w io.Writer, textEnc encoder.Encoder, m *meta.Meta, evalMeta encoder.EvalMetaFunc) { for _, p := range m.ComputedPairs() { io.WriteString(w, `\n") } } -func acceptBlocks(env *html.EncEnvironment, bs *ast.BlockSlice) error { +func acceptBlocks(env *html.EncEnvironment, bs *ast.BlockSlice) (int, error) { lst := sexprenc.GetSexpr(bs) sxpf.Eval(env, lst) - return env.GetError() + return 0, env.GetError() } -func acceptInlines(env *html.EncEnvironment, is *ast.InlineSlice) error { +func acceptInlines(env *html.EncEnvironment, is *ast.InlineSlice) (int, error) { lst := sexprenc.GetSexpr(is) sxpf.Eval(env, lst) - return env.GetError() + return 0, env.GetError() } Index: encoder/sexprenc/transform.go ================================================================== --- encoder/sexprenc/transform.go +++ encoder/sexprenc/transform.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2022-2023 Detlef Stern +// Copyright (c) 2022 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 @@ -76,11 +76,11 @@ case *ast.TableNode: return t.getTable(n) case *ast.TranscludeNode: return sxpf.NewPairFromValues(sexpr.SymTransclude, getAttributes(n.Attrs), getReference(n.Ref)) case *ast.BLOBNode: - return t.getBLOB(n) + return getBLOB(n) case *ast.TextNode: return sxpf.NewPairFromValues(sexpr.SymText, sxpf.NewString(n.Text)) case *ast.SpaceNode: if t.inVerse { return sxpf.NewPairFromValues(sexpr.SymSpace, sxpf.NewString(n.Lexeme)) @@ -278,20 +278,20 @@ func (t *transformer) getCell(cell *ast.TableCell) *sxpf.Pair { return sxpf.NewPair(mapGetS(alignmentSymbolS, cell.Align), t.getInlineSlice(cell.Inlines)) } -func (t *transformer) getBLOB(bn *ast.BLOBNode) *sxpf.Pair { +func getBLOB(bn *ast.BLOBNode) *sxpf.Pair { var lastValue sxpf.Value if bn.Syntax == meta.SyntaxSVG { lastValue = sxpf.NewString(string(bn.Blob)) } else { lastValue = getBase64String(bn.Blob) } return sxpf.NewPairFromValues( sexpr.SymBLOB, - t.getInlineSlice(bn.Description), + sxpf.NewString(bn.Title), sxpf.NewString(bn.Syntax), lastValue, ) } Index: encoder/zjsonenc/zjsonenc.go ================================================================== --- encoder/zjsonenc/zjsonenc.go +++ encoder/zjsonenc/zjsonenc.go @@ -1,18 +1,16 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 zjsonenc encodes the abstract syntax tree into JSON. -// -// Deprecated in v0.11 package zjsonenc import ( "fmt" "io" @@ -330,13 +328,13 @@ v.b.WriteByte('}') } func (v *visitor) visitBLOB(bn *ast.BLOBNode) { v.writeNodeStart(zjson.TypeBLOB) - if len(bn.Description) > 0 { + if bn.Title != "" { v.writeContentStart(zjson.NameString2) - ast.Walk(v, &bn.Description) + writeEscaped(&v.b, bn.Title) } v.writeContentStart(zjson.NameString) writeEscaped(&v.b, bn.Syntax) if bn.Syntax == meta.SyntaxSVG { v.writeContentStart(zjson.NameString3) Index: encoder/zmkenc/zmkenc.go ================================================================== --- encoder/zmkenc/zmkenc.go +++ encoder/zmkenc/zmkenc.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -10,36 +10,31 @@ // Package zmkenc encodes the abstract syntax tree back into Zettelmarkup. package zmkenc import ( - "bytes" "fmt" "io" "zettelstore.de/c/api" "zettelstore.de/c/attrs" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder" - "zettelstore.de/z/encoder/textenc" "zettelstore.de/z/strfun" ) func init() { - encoder.Register(api.EncoderZmk, func() encoder.Encoder { return Create() }) + encoder.Register(api.EncoderZmk, func() encoder.Encoder { return &myZE }) } -// Create an encoder. -func Create() *Encoder { return &myZE } +type zmkEncoder struct{} -type Encoder struct{} - -var myZE Encoder +var myZE zmkEncoder // WriteZettel writes the encoded zettel to the writer. -func (*Encoder) WriteZettel(w io.Writer, zn *ast.ZettelNode, evalMeta encoder.EvalMetaFunc) (int, error) { +func (*zmkEncoder) WriteZettel(w io.Writer, zn *ast.ZettelNode, evalMeta encoder.EvalMetaFunc) (int, error) { v := newVisitor(w) v.acceptMeta(zn.InhMeta, evalMeta) if zn.InhMeta.YamlSep { v.b.WriteString("---\n") } else { @@ -49,11 +44,11 @@ length, err := v.b.Flush() return length, err } // WriteMeta encodes meta data as zmk. -func (*Encoder) WriteMeta(w io.Writer, m *meta.Meta, evalMeta encoder.EvalMetaFunc) (int, error) { +func (*zmkEncoder) WriteMeta(w io.Writer, m *meta.Meta, evalMeta encoder.EvalMetaFunc) (int, error) { v := newVisitor(w) v.acceptMeta(m, evalMeta) length, err := v.b.Flush() return length, err } @@ -70,41 +65,40 @@ } v.b.WriteByte('\n') } } -func (ze *Encoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { +func (ze *zmkEncoder) WriteContent(w io.Writer, zn *ast.ZettelNode) (int, error) { return ze.WriteBlocks(w, &zn.Ast) } // WriteBlocks writes the content of a block slice to the writer. -func (*Encoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { +func (*zmkEncoder) WriteBlocks(w io.Writer, bs *ast.BlockSlice) (int, error) { v := newVisitor(w) ast.Walk(v, bs) length, err := v.b.Flush() return length, err } // WriteInlines writes an inline slice to the writer -func (*Encoder) WriteInlines(w io.Writer, is *ast.InlineSlice) (int, error) { +func (*zmkEncoder) WriteInlines(w io.Writer, is *ast.InlineSlice) (int, error) { v := newVisitor(w) ast.Walk(v, is) length, err := v.b.Flush() return length, err } // visitor writes the abstract syntax tree to an io.Writer. type visitor struct { b encoder.EncWriter - textEnc encoder.Encoder prefix []byte inVerse bool inlinePos int } func newVisitor(w io.Writer) *visitor { - return &visitor{b: encoder.NewEncWriter(w), textEnc: textenc.Create()} + return &visitor{b: encoder.NewEncWriter(w)} } func (v *visitor) Visit(node ast.Node) ast.Visitor { switch n := node.(type) { case *ast.BlockSlice: @@ -343,13 +337,12 @@ v.b.WriteStrings("@@@", bn.Syntax, "\n") v.b.Write(bn.Blob) v.b.WriteString("\n@@@\n") return } - var buf bytes.Buffer - v.textEnc.WriteInlines(&buf, &bn.Description) - v.b.WriteStrings("%% Unable to display BLOB with description '", buf.String(), "' and syntax '", bn.Syntax, "'.") + v.b.WriteStrings( + "%% Unable to display BLOB with title '", bn.Title, "' and syntax '", bn.Syntax, "'.") } var escapeSeqs = strfun.NewSet( "\\", "__", "**", "~~", "^^", ",,", ">>", `""`, "::", "''", "``", "++", "==", ) Index: encoding/atom/atom.go ================================================================== --- encoding/atom/atom.go +++ encoding/atom/atom.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2022-2023 Detlef Stern +// Copyright (c) 2022 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 @@ -11,10 +11,11 @@ // Package atom provides an Atom encoding. package atom import ( "bytes" + "context" "time" "zettelstore.de/c/api" "zettelstore.de/z/config" "zettelstore.de/z/domain/id" @@ -32,11 +33,11 @@ Title string Generator string NewURLBuilderAbs func() *api.URLBuilder } -func (c *Configuration) Setup(cfg config.Config) { +func (c *Configuration) Setup(ctx context.Context, cfg config.Config) { baseURL := kernel.Main.GetConfig(kernel.WebService, kernel.WebBaseURL).(string) c.Title = cfg.GetSiteName() c.Generator = (kernel.Main.GetConfig(kernel.CoreService, kernel.CoreProgname).(string) + " " + Index: evaluator/evaluator.go ================================================================== --- evaluator/evaluator.go +++ evaluator/evaluator.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2021-2023 Detlef Stern +// Copyright (c) 2021-2022 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 @@ -407,11 +407,11 @@ e.transcludeCount++ return createInlineErrorImage(en) } if syntax := zettel.Meta.GetDefault(api.KeySyntax, ""); parser.IsImageFormat(syntax) { - e.updateImageRefNode(en, zettel.Meta, syntax) + en.Syntax = syntax return en } else if !parser.IsASTParser(syntax) { // Not embeddable. e.transcludeCount++ return createInlineErrorText(ref, "Not", "embeddable (syntax="+syntax+")") @@ -458,23 +458,10 @@ panic(fmt.Sprintf("%v: %q (state %v) -> %v", err, ref.URL.Path, ref.State, ref)) } return zid } -func (e *evaluator) updateImageRefNode(en *ast.EmbedRefNode, m *meta.Meta, syntax string) { - en.Syntax = syntax - if len(en.Inlines) == 0 { - is := parser.ParseDescription(m) - if len(is) > 0 { - ast.Walk(e, &is) - if len(is) > 0 { - en.Inlines = is - } - } - } -} - func (e *evaluator) evalLiteralNode(ln *ast.LiteralNode) ast.InlineNode { if ln.Kind != ast.LiteralZettel { return ln } e.transcludeCount++ @@ -557,14 +544,18 @@ } if len(bs) == 0 { return nil } if bn, ok := bs[0].(*ast.BLOBNode); ok { + var ins ast.InlineSlice + if bn.Title != "" { + ins = ast.CreateInlineSliceFromWords(strings.Fields(bn.Title)...) + } return ast.InlineSlice{&ast.EmbedBLOBNode{ Blob: bn.Blob, Syntax: bn.Syntax, - Inlines: bn.Description, + Inlines: ins, }} } return nil } Index: evaluator/list.go ================================================================== --- evaluator/list.go +++ evaluator/list.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2022-2023 Detlef Stern +// Copyright (c) 2022 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 @@ -40,11 +40,11 @@ max: -1, title: rtConfig.GetSiteName(), } actions := q.Actions() if len(actions) == 0 { - return ap.createBlockNodeMeta("") + return ap.createBlockNodeMeta() } acts := make([]string, 0, len(actions)) for i, act := range actions { if strings.HasPrefix(act, "N") { @@ -67,32 +67,26 @@ ap.title = strings.Join(actions[i+1:], " ") break } acts = append(acts, act) } - var firstUnknownKey string for _, act := range acts { switch act { case "ATOM": return ap.createBlockNodeAtom(rtConfig) case "RSS": return ap.createBlockNodeRSS(rtConfig) - case "KEYS": - return ap.createBlockNodeMetaKeys() } key := strings.ToLower(act) switch meta.Type(key) { case meta.TypeWord: return ap.createBlockNodeWord(key) case meta.TypeTagSet: return ap.createBlockNodeTagSet(key) } - if firstUnknownKey == "" { - firstUnknownKey = key - } } - return ap.createBlockNodeMeta(firstUnknownKey) + return ap.createBlockNodeMeta() } type actionPara struct { ctx context.Context q *query.Query @@ -139,11 +133,13 @@ para := make(ast.InlineSlice, 0, len(ccs)) ccs.SortByName() for i, cat := range ccs { if i > 0 { - para = append(para, &ast.SpaceNode{Lexeme: " "}) + para = append(para, &ast.SpaceNode{ + Lexeme: " ", + }) } buf.WriteString(cat.Name) para = append(para, &ast.LinkNode{ Attrs: countMap[cat.Count], @@ -158,11 +154,13 @@ Inlines: ast.InlineSlice{&ast.TextNode{Text: strconv.Itoa(cat.Count)}}, }, ) buf.Truncate(bufLen) } - return &ast.ParaNode{Inlines: para} + return &ast.ParaNode{ + Inlines: para, + } } func (ap *actionPara) limitTags(ccs meta.CountedCategories) meta.CountedCategories { if min, max := ap.min, ap.max; min > 0 || max > 0 { if min < 0 { @@ -182,70 +180,16 @@ } } return ccs } -func (ap *actionPara) createBlockNodeMetaKeys() ast.BlockNode { - arr := make(meta.Arrangement, 128) - for _, m := range ap.ml { - for k := range m.Map() { - arr[k] = append(arr[k], m) - } - } - if len(arr) == 0 { - return nil - } - ccs := arr.Counted() - ccs.SortByName() - - var buf bytes.Buffer - bufLen := ap.prepareSimpleQuery(&buf) - items := make([]ast.ItemSlice, 0, len(ccs)) - for _, cat := range ccs { - buf.WriteString(cat.Name) - buf.WriteString(api.ExistOperator) - q1 := buf.String() - buf.Truncate(bufLen) - buf.WriteString(api.ActionSeparator) - buf.WriteString(cat.Name) - q2 := buf.String() - buf.Truncate(bufLen) - - items = append(items, ast.ItemSlice{ast.CreateParaNode( - &ast.LinkNode{ - Attrs: nil, - Ref: ast.ParseReference(q1), - Inlines: ast.InlineSlice{&ast.TextNode{Text: cat.Name}}, - }, - &ast.SpaceNode{Lexeme: " "}, - &ast.TextNode{Text: "(" + strconv.Itoa(cat.Count) + ", "}, - &ast.LinkNode{ - Attrs: nil, - Ref: ast.ParseReference(q2), - Inlines: ast.InlineSlice{&ast.TextNode{Text: "values"}}, - }, - &ast.TextNode{Text: ")"}, - )}) - } - return &ast.NestedListNode{ - Kind: ap.kind, - Items: items, - Attrs: nil, - } -} - -func (ap *actionPara) createBlockNodeMeta(key string) ast.BlockNode { +func (ap *actionPara) createBlockNodeMeta() ast.BlockNode { if len(ap.ml) == 0 { return nil } items := make([]ast.ItemSlice, 0, len(ap.ml)) for _, m := range ap.ml { - if key != "" { - if _, found := m.Get(key); !found { - continue - } - } zid := m.Zid.String() title, found := m.Get(api.KeyTitle) if !found { title = zid } @@ -269,27 +213,22 @@ ccs := meta.CreateArrangement(ap.ml, key).Counted() if len(ccs) == 0 { return nil, 0 } - ap.prepareSimpleQuery(buf) - buf.WriteString(key) - buf.WriteString(api.SearchOperatorHas) - bufLen := buf.Len() - - return ccs, bufLen -} - -func (ap *actionPara) prepareSimpleQuery(buf *bytes.Buffer) int { sea := ap.q.Clone() sea.RemoveActions() buf.WriteString(ast.QueryPrefix) sea.Print(buf) if buf.Len() > len(ast.QueryPrefix) { buf.WriteByte(' ') } - return buf.Len() + buf.WriteString(key) + buf.WriteByte(':') + bufLen := buf.Len() + + return ccs, bufLen } const fontSizes = 6 // Must be the number of CSS classes zs-font-size-* in base.css const fontSizes64 = float64(fontSizes) @@ -359,15 +298,15 @@ } } func (ap *actionPara) createBlockNodeAtom(cfg config.Config) ast.BlockNode { var atomConfig atom.Configuration - atomConfig.Setup(cfg) + atomConfig.Setup(ap.ctx, cfg) atomConfig.Title = ap.title data := atomConfig.Marshal(ap.q, ap.ml) return &ast.VerbatimNode{ Kind: ast.VerbatimProg, Attrs: attrs.Attributes{"lang": "xml"}, Content: data, } } Index: go.mod ================================================================== --- go.mod +++ go.mod @@ -5,12 +5,12 @@ require ( codeberg.org/t73fde/sxpf v0.0.0-20220719090054-749a39d0a7a0 github.com/fsnotify/fsnotify v1.6.0 github.com/pascaldekloe/jwt v1.12.0 github.com/yuin/goldmark v1.5.3 - golang.org/x/crypto v0.5.0 - golang.org/x/term v0.4.0 - golang.org/x/text v0.6.0 - zettelstore.de/c v0.10.0 + golang.org/x/crypto v0.4.0 + golang.org/x/term v0.3.0 + golang.org/x/text v0.5.0 + zettelstore.de/c v0.9.0 ) -require golang.org/x/sys v0.4.0 // indirect +require golang.org/x/sys v0.3.0 // indirect Index: go.sum ================================================================== --- go.sum +++ go.sum @@ -4,16 +4,16 @@ github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/pascaldekloe/jwt v1.12.0 h1:imQSkPOtAIBAXoKKjL9ZVJuF/rVqJ+ntiLGpLyeqMUQ= github.com/pascaldekloe/jwt v1.12.0/go.mod h1:LiIl7EwaglmH1hWThd/AmydNCnHf/mmfluBlNqHbk8U= github.com/yuin/goldmark v1.5.3 h1:3HUJmBFbQW9fhQOzMgseU134xfi6hU+mjWywx5Ty+/M= github.com/yuin/goldmark v1.5.3/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= -golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= +golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8= +golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg= -golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= -golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= -golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -zettelstore.de/c v0.10.0 h1:e5VOrH5aEEojNrUfO/721dsiHsp/yuTvNPF6DNsgA3U= -zettelstore.de/c v0.10.0/go.mod h1:+SoneUhKQ81A2Id/bC6FdDYYQAHYfVryh7wHFnnklew= +golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI= +golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= +golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= +golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +zettelstore.de/c v0.9.0 h1:QkPHKQcJBA5qqEUwy370tNqVDWjhTioAzSf2cRvAdn8= +zettelstore.de/c v0.9.0/go.mod h1:+SoneUhKQ81A2Id/bC6FdDYYQAHYfVryh7wHFnnklew= Index: kernel/impl/cfg.go ================================================================== --- kernel/impl/cfg.go +++ kernel/impl/cfg.go @@ -64,10 +64,11 @@ return vis, nil }, true, }, keyExpertMode: {"Expert mode", parseBool, true}, + config.KeyFooterHTML: {"Footer HTML", parseString, true}, config.KeyFooterZettel: {"Footer Zettel", parseInvalidZid, true}, config.KeyHomeZettel: {"Home zettel", parseZid, true}, kernel.ConfigInsecureHTML: { "Insecure HTML", cs.noFrozen(func(val string) (any, error) { @@ -98,10 +99,11 @@ cs.next = interfaceMap{ keyDefaultCopyright: "", keyDefaultLicense: "", keyDefaultVisibility: meta.VisibilityLogin, keyExpertMode: false, + config.KeyFooterHTML: "", config.KeyFooterZettel: id.Invalid, config.KeyHomeZettel: id.DefaultHomeZid, kernel.ConfigInsecureHTML: config.NoHTML, api.KeyLang: api.ValueLangEN, config.KeyMarkerExternal: "➚", Index: parser/blob/blob.go ================================================================== --- parser/blob/blob.go +++ parser/blob/blob.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -10,10 +10,11 @@ // Package blob provides a parser of binary data. package blob import ( + "zettelstore.de/c/api" "zettelstore.de/z/ast" "zettelstore.de/z/domain/meta" "zettelstore.de/z/input" "zettelstore.de/z/parser" ) @@ -59,13 +60,14 @@ func parseBlocks(inp *input.Input, m *meta.Meta, syntax string) ast.BlockSlice { if p := parser.Get(syntax); p != nil { syntax = p.Name } + title := m.GetDefault(api.KeyTitle, "") return ast.BlockSlice{&ast.BLOBNode{ - Description: parser.ParseDescription(m), - Syntax: syntax, - Blob: []byte(inp.Src), + Title: title, + Syntax: syntax, + Blob: []byte(inp.Src), }} } func parseInlines(*input.Input, string) ast.InlineSlice { return nil } Index: parser/draw/draw.go ================================================================== --- parser/draw/draw.go +++ parser/draw/draw.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2022-2023 Detlef Stern +// Copyright (c) 2022 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 @@ -60,13 +60,13 @@ svg := canvasToSVG(canvas, font, int(scaleX), int(scaleY)) if len(svg) == 0 { return ast.BlockSlice{ast.CreateParaNode(noSVGErrMsg()...)} } return ast.BlockSlice{&ast.BLOBNode{ - Description: parser.ParseDescription(m), - Syntax: meta.SyntaxSVG, - Blob: svg, + Title: "", + Syntax: meta.SyntaxSVG, + Blob: svg, }} } func parseInlines(inp *input.Input, _ string) ast.InlineSlice { canvas, err := newCanvas(inp.Src[inp.Pos:]) @@ -107,13 +107,13 @@ svg := canvasToSVG(canvas, font, scaleX, scaleY) if len(svg) == 0 { return ast.CreateParaNode(noSVGErrMsg()...) } return &ast.BLOBNode{ - Description: nil, // TODO: look for attribute "summary" / "title" - Syntax: meta.SyntaxSVG, - Blob: svg, + Title: "", + Syntax: meta.SyntaxSVG, + Blob: svg, } } func getScale(a attrs.Attributes, key string, defVal int) int { if val, found := a.Get(key); found { Index: parser/draw/svg.go ================================================================== --- parser/draw/svg.go +++ parser/draw/svg.go @@ -37,11 +37,11 @@ font = "monospace" } var b bytes.Buffer fmt.Fprintf(&b, - ``, + ``, (c.size().X+1)*scaleX, (c.size().Y+1)*scaleY) writeMarkerDefs(&b, c, scaleX, scaleY) // 3 passes, first closed paths, then open paths, then text. writeClosedPaths(&b, c, scaleX, scaleY) Index: parser/draw/svg_test.go ================================================================== --- parser/draw/svg_test.go +++ parser/draw/svg_test.go @@ -35,29 +35,29 @@ []string{ "+--.", "|Hi:", "+--+", }, - 482, + 486, }, // 2 Ticks and dots in lines. { []string{ " ------x----->", "", " <-----*------", }, - 1084, + 1088, }, // 3 Just text { []string{ " foo", }, - 261, + 265, }, } for i, line := range data { canvas, err := newCanvas([]byte(strings.Join(line.input, "\n"))) if err != nil { Index: parser/parser.go ================================================================== --- parser/parser.go +++ parser/parser.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -130,25 +130,10 @@ in := ParseMetadata(value) cleaner.CleanInlineLinks(&in) return in } -// ParseDescription returns a suitable description stored in the metadata as an inline slice. -func ParseDescription(m *meta.Meta) ast.InlineSlice { - if m == nil { - return nil - } - descr, found := m.Get(api.KeySummary) - if !found { - descr, found = m.Get(api.KeyTitle) - } - if !found { - return nil - } - return ParseMetadataNoLink(descr) -} - // ParseZettel parses the zettel based on the syntax. func ParseZettel(ctx context.Context, zettel domain.Zettel, syntax string, rtConfig config.Config) *ast.ZettelNode { m := zettel.Meta inhMeta := m if rtConfig != nil { Index: query/query.go ================================================================== --- query/query.go +++ query/query.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -42,13 +42,10 @@ type Query struct { // Fields to be used for selecting preMatch MetaMatchFunc // Match that must be true terms []conjTerms - // Allow to create predictable randomness - seed int - // Fields to be used for sorting order []sortOrder offset int // <= 0: no offset limit int // <= 0: no limit @@ -143,11 +140,10 @@ // } if len(term.search) > 0 { c.terms[i].search = append([]expValue{}, term.search...) } } - c.seed = q.seed if len(q.order) > 0 { c.order = append([]sortOrder{}, q.order...) } c.offset = q.offset c.limit = q.limit @@ -217,25 +213,10 @@ } q.preMatch = preMatch return q } -// SetSeed sets a seed value. -func (q *Query) SetSeed(seed int) *Query { - q = createIfNeeded(q) - q.seed = seed - return q -} - -// GetSeed returns the seed value if one was set. -func (q *Query) GetSeed() (int, bool) { - if q == nil { - return 0, false - } - return q.seed, q.seed > 0 -} - // SetLimit sets the given limit of the query object. func (q *Query) SetLimit(limit int) *Query { q = createIfNeeded(q) if limit < 0 { limit = 0 @@ -388,11 +369,13 @@ sort.Slice(metaList, func(i, j int) bool { return metaList[i].Zid > metaList[j].Zid }) if q == nil { return metaList } } else if q.order[0].isRandom() { - metaList = q.sortRandomly(metaList) + rand.Shuffle(len(metaList), func(i, j int) { + metaList[i], metaList[j] = metaList[j], metaList[i] + }) } else { sort.Slice(metaList, createSortFunc(q.order, metaList)) } if q.offset > 0 { @@ -402,27 +385,10 @@ metaList = metaList[q.offset:] } return q.Limit(metaList) } -func (q *Query) setSeed() { - if q != nil && q.seed <= 0 { - q.seed = int(rand.Intn(10000) + 1) - } -} - -func (q *Query) sortRandomly(metaList []*meta.Meta) []*meta.Meta { - q.setSeed() - sort.Slice(metaList, func(i, j int) bool { return metaList[i].Zid > metaList[j].Zid }) - rnd := rand.New(rand.NewSource(int64(q.seed))) - rnd.Shuffle( - len(metaList), - func(i, j int) { metaList[i], metaList[j] = metaList[j], metaList[i] }, - ) - return metaList -} - // Limit returns only s.GetLimit() elements of the given list. func (q *Query) Limit(metaList []*meta.Meta) []*meta.Meta { if q == nil { return metaList } Index: tools/build.go ================================================================== --- tools/build.go +++ tools/build.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2021-2023 Detlef Stern +// Copyright (c) 2021-2022 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 @@ -189,25 +189,25 @@ func checkUnparam(forRelease bool) error { path, err := findExecStrict("unparam", forRelease) if path == "" { return err } - out, err := executeCommand(nil, path, "./...") - if err != nil { - fmt.Fprintln(os.Stderr, "Some unparam problems found") - if len(out) > 0 { - fmt.Fprintln(os.Stderr, out) - } - } - if forRelease { - if out2, err2 := executeCommand(nil, path, "-exported", "-tests", "./..."); err2 != nil { - fmt.Fprintln(os.Stderr, "Some optional unparam problems found") - if len(out2) > 0 { - fmt.Fprintln(os.Stderr, out2) - } - } - } + // out, err := executeCommand(nil, path, "./...") + // if err != nil { + // fmt.Fprintln(os.Stderr, "Some unparam problems found") + // if len(out) > 0 { + // fmt.Fprintln(os.Stderr, out) + // } + // } + // if forRelease { + // if out2, err2 := executeCommand(nil, path, "-exported", "-tests", "./..."); err2 != nil { + // fmt.Fprintln(os.Stderr, "Some optional unparam problems found") + // if len(out2) > 0 { + // fmt.Fprintln(os.Stderr, out2) + // } + // } + // } return err } func findExecStrict(cmd string, forRelease bool) (string, error) { path := findExec(cmd) @@ -307,11 +307,10 @@ func cmdBuild() error { return doBuild(directProxy, getVersion(), "bin/zettelstore") } func doBuild(env []string, version, target string) error { - env = append(env, "CGO_ENABLED=0") out, err := executeCommand( env, "go", "build", "-tags", "osusergo,netgo", "-trimpath", Index: web/adapter/api/create_zettel.go ================================================================== --- web/adapter/api/create_zettel.go +++ web/adapter/api/create_zettel.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2021-2023 Detlef Stern +// Copyright (c) 2021-2022 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 @@ -13,70 +13,67 @@ import ( "bytes" "net/http" "zettelstore.de/c/api" - "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/content" ) + +// MakePostCreatePlainZettelHandler creates a new HTTP handler to store content of +// an existing zettel. +func (a *API) MakePostCreatePlainZettelHandler(createZettel *usecase.CreateZettel) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + zettel, err := buildZettelFromPlainData(r, id.Invalid) + if err != nil { + a.reportUsecaseError(w, adapter.NewErrBadRequest(err.Error())) + return + } + + newZid, err := createZettel.Run(ctx, zettel) + if err != nil { + a.reportUsecaseError(w, err) + return + } + u := a.NewURLBuilder('z').SetZid(api.ZettelID(newZid.String())).String() + h := adapter.PrepareHeader(w, content.PlainText) + h.Set(api.HeaderLocation, u) + w.WriteHeader(http.StatusCreated) + _, err = w.Write(newZid.Bytes()) + a.log.IfErr(err).Zid(newZid).Msg("Create Plain Zettel") + } +} // MakePostCreateZettelHandler creates a new HTTP handler to store content of // an existing zettel. func (a *API) MakePostCreateZettelHandler(createZettel *usecase.CreateZettel) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - q := r.URL.Query() - enc, encStr := getEncoding(r, q) - var zettel domain.Zettel - var err error - switch enc { - case api.EncoderPlain: - zettel, err = buildZettelFromPlainData(r, id.Invalid) - case api.EncoderJson: - zettel, err = buildZettelFromJSONData(r, id.Invalid) - default: - http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) - return - } + ctx := r.Context() + zettel, err := buildZettelFromJSONData(r, id.Invalid) if err != nil { a.reportUsecaseError(w, adapter.NewErrBadRequest(err.Error())) return } - ctx := r.Context() newZid, err := createZettel.Run(ctx, zettel) if err != nil { a.reportUsecaseError(w, err) return } - - var result []byte - var contentType string - location := a.NewURLBuilder('z').SetZid(api.ZettelID(newZid.String())) - switch enc { - case api.EncoderPlain: - result = newZid.Bytes() - contentType = content.PlainText - case api.EncoderJson: - var buf bytes.Buffer - err = encodeJSONData(&buf, api.ZidJSON{ID: api.ZettelID(newZid.String())}) - if err != nil { - a.log.Fatal().Err(err).Zid(newZid).Msg("Unable to store new Zid in buffer") - http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) - return - } - result = buf.Bytes() - contentType = content.JSON - location.AppendKVQuery(api.QueryKeyEncoding, api.EncodingJson) - default: - panic(encStr) - } - - h := adapter.PrepareHeader(w, contentType) - h.Set(api.HeaderLocation, location.String()) - w.WriteHeader(http.StatusCreated) - _, err = w.Write(result) - a.log.IfErr(err).Zid(newZid).Msg("Create Zettel") + var buf bytes.Buffer + err = encodeJSONData(&buf, api.ZidJSON{ID: api.ZettelID(newZid.String())}) + if err != nil { + a.log.Fatal().Err(err).Zid(newZid).Msg("Unable to store new Zid in buffer") + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + + h := adapter.PrepareHeader(w, content.JSON) + h.Set(api.HeaderLocation, a.NewURLBuilder('j').SetZid(api.ZettelID(newZid.String())).String()) + w.WriteHeader(http.StatusCreated) + _, err = w.Write(buf.Bytes()) + a.log.IfErr(err).Zid(newZid).Msg("Create JSON Zettel") } } ADDED web/adapter/api/get_eval_zettel.go Index: web/adapter/api/get_eval_zettel.go ================================================================== --- web/adapter/api/get_eval_zettel.go +++ web/adapter/api/get_eval_zettel.go @@ -0,0 +1,46 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2020-2022 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 api + +import ( + "net/http" + + "zettelstore.de/c/api" + "zettelstore.de/z/ast" + "zettelstore.de/z/domain/id" + "zettelstore.de/z/encoder" + "zettelstore.de/z/usecase" +) + +// MakeGetEvalZettelHandler creates a new HTTP handler to return a evaluated zettel. +func (a *API) MakeGetEvalZettelHandler(evaluate usecase.Evaluate) 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() + q := r.URL.Query() + enc, encStr := getEncoding(r, q, encoder.GetDefaultEncoding()) + part := getPart(q, partContent) + zn, err := evaluate.Run(ctx, zid, q.Get(api.KeySyntax)) + if err != nil { + a.reportUsecaseError(w, err) + return + } + evalMeta := func(value string) ast.InlineSlice { + return evaluate.RunMetadata(ctx, value) + } + a.writeEncodedZettelPart(w, zn, evalMeta, enc, encStr, part) + } +} ADDED web/adapter/api/get_parsed_zettel.go Index: web/adapter/api/get_parsed_zettel.go ================================================================== --- web/adapter/api/get_parsed_zettel.go +++ web/adapter/api/get_parsed_zettel.go @@ -0,0 +1,82 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2020-2022 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 api provides api handlers for web requests. +package api + +import ( + "bytes" + "fmt" + "net/http" + + "zettelstore.de/c/api" + "zettelstore.de/z/ast" + "zettelstore.de/z/domain/id" + "zettelstore.de/z/encoder" + "zettelstore.de/z/parser" + "zettelstore.de/z/usecase" + "zettelstore.de/z/web/adapter" + "zettelstore.de/z/web/content" +) + +// MakeGetParsedZettelHandler creates a new HTTP handler to return a parsed zettel. +func (a *API) MakeGetParsedZettelHandler(parseZettel usecase.ParseZettel) 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() + enc, encStr := getEncoding(r, q, encoder.GetDefaultEncoding()) + part := getPart(q, partContent) + zn, err := parseZettel.Run(r.Context(), zid, q.Get(api.KeySyntax)) + if err != nil { + a.reportUsecaseError(w, err) + return + } + a.writeEncodedZettelPart(w, zn, parser.ParseMetadata, enc, encStr, part) + } +} + +func (a *API) writeEncodedZettelPart( + w http.ResponseWriter, zn *ast.ZettelNode, + evalMeta encoder.EvalMetaFunc, + enc api.EncodingEnum, encStr string, part partType, +) { + encdr := encoder.Create(enc) + if encdr == nil { + adapter.BadRequest(w, fmt.Sprintf("Zettel %q not available in encoding %q", zn.Meta.Zid, encStr)) + return + } + var err error + var buf bytes.Buffer + switch part { + case partZettel: + _, err = encdr.WriteZettel(&buf, zn, evalMeta) + case partMeta: + _, err = encdr.WriteMeta(&buf, zn.InhMeta, evalMeta) + case partContent: + _, err = encdr.WriteContent(&buf, zn) + } + if err != nil { + a.log.Fatal().Err(err).Zid(zn.Zid).Msg("Unable to store data in buffer") + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + if buf.Len() == 0 { + w.WriteHeader(http.StatusNoContent) + return + } + + err = writeBuffer(w, &buf, content.MIMEFromEncoding(enc)) + a.log.IfErr(err).Zid(zn.Zid).Msg("Write Encoded Zettel") +} Index: web/adapter/api/get_zettel.go ================================================================== --- web/adapter/api/get_zettel.go +++ web/adapter/api/get_zettel.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -11,192 +11,127 @@ package api import ( "bytes" "context" - "fmt" "net/http" "zettelstore.de/c/api" - "zettelstore.de/z/ast" "zettelstore.de/z/box" + "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" - "zettelstore.de/z/encoder" - "zettelstore.de/z/parser" "zettelstore.de/z/usecase" - "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/content" ) -// MakeGetZettelHandler creates a new HTTP handler to return a zettel in various encodings. -func (a *API) MakeGetZettelHandler(getMeta usecase.GetMeta, getZettel usecase.GetZettel, parseZettel usecase.ParseZettel, evaluate usecase.Evaluate) http.HandlerFunc { +// MakeGetZettelHandler creates a new HTTP handler to return a zettel. +func (a *API) MakeGetZettelHandler(getZettel usecase.GetZettel) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + z, err := a.getZettelFromPath(ctx, w, r, getZettel) + if err != nil { + return + } + m := z.Meta + + var buf bytes.Buffer + zContent, encoding := z.Content.Encode() + err = encodeJSONData(&buf, api.ZettelJSON{ + ID: api.ZettelID(m.Zid.String()), + Meta: m.Map(), + Encoding: encoding, + Content: zContent, + Rights: a.getRights(ctx, m), + }) + if err != nil { + a.log.Fatal().Err(err).Zid(m.Zid).Msg("Unable to store zettel in buffer") + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + + err = writeBuffer(w, &buf, content.JSON) + a.log.IfErr(err).Zid(m.Zid).Msg("Write JSON Zettel") + } +} + +// MakeGetPlainZettelHandler creates a new HTTP handler to return a zettel in plain formar +func (a *API) MakeGetPlainZettelHandler(getZettel usecase.GetZettel) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + z, err := a.getZettelFromPath(box.NoEnrichContext(r.Context()), w, r, getZettel) + if err != nil { + return + } + + var buf bytes.Buffer + var contentType string + switch getPart(r.URL.Query(), partContent) { + case partZettel: + _, err = z.Meta.Write(&buf) + if err == nil { + err = buf.WriteByte('\n') + } + if err == nil { + _, err = z.Content.Write(&buf) + } + case partMeta: + contentType = content.PlainText + _, err = z.Meta.Write(&buf) + case partContent: + contentType = content.MIMEFromSyntax(z.Meta.GetDefault(api.KeySyntax, "")) + _, err = z.Content.Write(&buf) + } + if err != nil { + a.log.Fatal().Err(err).Zid(z.Meta.Zid).Msg("Unable to store plain zettel/part in buffer") + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + err = writeBuffer(w, &buf, contentType) + a.log.IfErr(err).Zid(z.Meta.Zid).Msg("Write Plain Zettel") + } +} + +func (a *API) getZettelFromPath(ctx context.Context, w http.ResponseWriter, r *http.Request, getZettel usecase.GetZettel) (domain.Zettel, error) { + zid, err := id.Parse(r.URL.Path[1:]) + if err != nil { + http.NotFound(w, r) + return domain.Zettel{}, err + } + + z, err := getZettel.Run(ctx, zid) + if err != nil { + a.reportUsecaseError(w, err) + return domain.Zettel{}, err + } + return z, nil +} + +// MakeGetMetaHandler creates a new HTTP handler to return metadata of a zettel. +func (a *API) MakeGetMetaHandler(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 } - q := r.URL.Query() - part := getPart(q, partContent) - ctx := r.Context() - switch enc, encStr := getEncoding(r, q); enc { - case api.EncoderPlain: - a.writePlainData(w, ctx, zid, part, getMeta, getZettel) - - case api.EncoderJson: - a.writeJSONData(w, ctx, zid, part, getMeta, getZettel) - - default: - var zn *ast.ZettelNode - var em func(value string) ast.InlineSlice - if q.Has(api.QueryKeyParseOnly) { - zn, err = parseZettel.Run(ctx, zid, q.Get(api.KeySyntax)) - em = parser.ParseMetadata - } else { - zn, err = evaluate.Run(ctx, zid, q.Get(api.KeySyntax)) - em = func(value string) ast.InlineSlice { - return evaluate.RunMetadata(ctx, value) - } - } - if err != nil { - a.reportUsecaseError(w, err) - return - } - a.writeEncodedZettelPart(w, zn, em, enc, encStr, part) - } - } -} - -func (a *API) writePlainData(w http.ResponseWriter, ctx context.Context, zid id.Zid, part partType, getMeta usecase.GetMeta, getZettel usecase.GetZettel) { - var buf bytes.Buffer - var contentType string - var err error - - switch part { - case partZettel: - z, err2 := getZettel.Run(box.NoEnrichContext(ctx), zid) - if err2 != nil { - a.reportUsecaseError(w, err2) - return - } - _, err2 = z.Meta.Write(&buf) - if err2 == nil { - err2 = buf.WriteByte('\n') - } - if err2 == nil { - _, err = z.Content.Write(&buf) - } - - case partMeta: - m, err2 := getMeta.Run(box.NoEnrichContext(ctx), zid) - if err2 != nil { - a.reportUsecaseError(w, err2) - return - } - contentType = content.PlainText - _, err = m.Write(&buf) - - case partContent: - z, err2 := getZettel.Run(box.NoEnrichContext(ctx), zid) - if err2 != nil { - a.reportUsecaseError(w, err2) - return - } - contentType = content.MIMEFromSyntax(z.Meta.GetDefault(api.KeySyntax, "")) - _, err = z.Content.Write(&buf) - } - - if err != nil { - a.log.Fatal().Err(err).Zid(zid).Msg("Unable to store plain zettel/part in buffer") - http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) - return - } - err = writeBuffer(w, &buf, contentType) - a.log.IfErr(err).Zid(zid).Msg("Write Plain data") -} - -func (a *API) writeJSONData(w http.ResponseWriter, ctx context.Context, zid id.Zid, part partType, getMeta usecase.GetMeta, getZettel usecase.GetZettel) { - var buf bytes.Buffer - var err error - - switch part { - case partZettel: - z, err2 := getZettel.Run(ctx, zid) - if err2 != nil { - a.reportUsecaseError(w, err2) - return - } - zContent, encoding := z.Content.Encode() - err = encodeJSONData(&buf, api.ZettelJSON{ - ID: api.ZettelID(zid.String()), - Meta: z.Meta.Map(), - Encoding: encoding, - Content: zContent, - Rights: a.getRights(ctx, z.Meta), - }) - - case partMeta: - m, err2 := getMeta.Run(ctx, zid) - if err2 != nil { - a.reportUsecaseError(w, err2) - return - } + ctx := r.Context() + m, err := getMeta.Run(ctx, zid) + if err != nil { + a.reportUsecaseError(w, err) + return + } + + var buf bytes.Buffer err = encodeJSONData(&buf, api.MetaJSON{ Meta: m.Map(), Rights: a.getRights(ctx, m), }) - - case partContent: - z, err2 := getZettel.Run(ctx, zid) - if err2 != nil { - a.reportUsecaseError(w, err2) - return - } - zContent, encoding := z.Content.Encode() - err = encodeJSONData(&buf, api.ZettelContentJSON{ - Encoding: encoding, - Content: zContent, - }) - } - if err != nil { - a.log.Fatal().Err(err).Zid(zid).Msg("Unable to store zettel in buffer") - http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) - return - } - err = writeBuffer(w, &buf, content.JSON) - a.log.IfErr(err).Zid(zid).Msg("Write JSON data") -} - -func (a *API) writeEncodedZettelPart( - w http.ResponseWriter, zn *ast.ZettelNode, - evalMeta encoder.EvalMetaFunc, - enc api.EncodingEnum, encStr string, part partType, -) { - encdr := encoder.Create(enc) - if encdr == nil { - adapter.BadRequest(w, fmt.Sprintf("Zettel %q not available in encoding %q", zn.Meta.Zid, encStr)) - return - } - var err error - var buf bytes.Buffer - switch part { - case partZettel: - _, err = encdr.WriteZettel(&buf, zn, evalMeta) - case partMeta: - _, err = encdr.WriteMeta(&buf, zn.InhMeta, evalMeta) - case partContent: - _, err = encdr.WriteContent(&buf, zn) - } - if err != nil { - a.log.Fatal().Err(err).Zid(zn.Zid).Msg("Unable to store data in buffer") - http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) - return - } - if buf.Len() == 0 { - w.WriteHeader(http.StatusNoContent) - return - } - - err = writeBuffer(w, &buf, content.MIMEFromEncoding(enc)) - a.log.IfErr(err).Zid(zn.Zid).Msg("Write Encoded Zettel") + if err != nil { + a.log.Fatal().Err(err).Zid(zid).Msg("Unable to store metadata in buffer") + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + + err = writeBuffer(w, &buf, content.JSON) + a.log.IfErr(err).Zid(zid).Msg("Write JSON Meta") + } } ADDED web/adapter/api/get_zettel_list.go Index: web/adapter/api/get_zettel_list.go ================================================================== --- web/adapter/api/get_zettel_list.go +++ web/adapter/api/get_zettel_list.go @@ -0,0 +1,46 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2020-2022 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 api + +import ( + "bytes" + "fmt" + "net/http" + + "zettelstore.de/z/usecase" + "zettelstore.de/z/web/adapter" + "zettelstore.de/z/web/content" +) + +// MakeListPlainHandler creates a new HTTP handler for the use case "list some zettel". +func (a *API) MakeListPlainHandler(listMeta usecase.ListMeta) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + metaList, err := listMeta.Run(ctx, adapter.GetQuery(r.URL.Query())) + if err != nil { + a.reportUsecaseError(w, err) + return + } + + var buf bytes.Buffer + for _, m := range metaList { + _, err = fmt.Fprintln(&buf, m.Zid.String(), m.GetTitle()) + if err != nil { + a.log.Fatal().Err(err).Msg("Unable to store plain list in buffer") + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + } + + err = writeBuffer(w, &buf, content.PlainText) + a.log.IfErr(err).Msg("Write Plain List") + } +} Index: web/adapter/api/query.go ================================================================== --- web/adapter/api/query.go +++ web/adapter/api/query.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2022-2023 Detlef Stern +// Copyright (c) 2022 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 @@ -10,11 +10,11 @@ package api import ( "bytes" - "fmt" + "context" "io" "net/http" "strconv" "strings" @@ -28,163 +28,111 @@ // MakeQueryHandler creates a new HTTP handler to perform a query. func (a *API) MakeQueryHandler(listMeta usecase.ListMeta) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - q := r.URL.Query() - sq := adapter.GetQuery(q) + q := adapter.GetQuery(r.URL.Query()) + + metaList, err := listMeta.Run(ctx, q) + if err != nil { + a.reportUsecaseError(w, err) + return + } - metaList, err := listMeta.Run(ctx, sq) + var buf bytes.Buffer + contentType, err := a.queryAction(ctx, &buf, q, metaList) if err != nil { a.reportUsecaseError(w, err) return } - - var encoder zettelEncoder - var contentType string - switch enc, _ := getEncoding(r, q); enc { - case api.EncoderPlain: - encoder = &plainZettelEncoder{} - contentType = content.PlainText - - case api.EncoderJson: - encoder = &jsonZettelEncoder{ - sq: sq, - getRights: func(m *meta.Meta) api.ZettelRights { return a.getRights(ctx, m) }, - } - contentType = content.JSON - - default: - http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) - return - } - - var buf bytes.Buffer - err = queryAction(&buf, encoder, metaList, sq) - if err != nil { - a.log.Error().Err(err).Str("query", sq.String()).Msg("execute query action") - http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) - } - - err = writeBuffer(w, &buf, contentType) - a.log.IfErr(err).Msg("write result buffer") - } -} -func queryAction(w io.Writer, enc zettelEncoder, ml []*meta.Meta, sq *query.Query) error { - min, max := -1, -1 - if actions := sq.Actions(); len(actions) > 0 { + err = writeBuffer(w, &buf, contentType) + a.log.IfErr(err).Msg("write action") + } +} + +func (a *API) queryAction(ctx context.Context, w io.Writer, q *query.Query, ml []*meta.Meta) (string, error) { + ap := actionPara{ + w: w, + q: q, + ml: ml, + min: -1, + max: -1, + } + if actions := q.Actions(); len(actions) > 0 { acts := make([]string, 0, len(actions)) for _, act := range actions { if strings.HasPrefix(act, "MIN") { if num, err := strconv.Atoi(act[3:]); err == nil && num > 0 { - min = num + ap.min = num continue } } if strings.HasPrefix(act, "MAX") { if num, err := strconv.Atoi(act[3:]); err == nil && num > 0 { - max = num + ap.max = num continue } } acts = append(acts, act) } for _, act := range acts { key := strings.ToLower(act) switch meta.Type(key) { case meta.TypeWord, meta.TypeTagSet: - return encodeKeyArrangement(w, enc, ml, key, min, max) - } - } - } - return enc.writeMetaList(w, ml) -} - -func encodeKeyArrangement(w io.Writer, enc zettelEncoder, ml []*meta.Meta, key string, min, max int) error { - arr0 := meta.CreateArrangement(ml, key) - arr := make(meta.Arrangement, len(arr0)) - for k0, ml0 := range arr0 { - if len(ml0) < min || (max > 0 && len(ml0) > max) { - continue - } - arr[k0] = ml0 - } - return enc.writeArrangement(w, arr) -} - -type zettelEncoder interface { - writeMetaList(w io.Writer, ml []*meta.Meta) error - writeArrangement(w io.Writer, arr meta.Arrangement) error -} - -type plainZettelEncoder struct{} - -func (*plainZettelEncoder) writeMetaList(w io.Writer, ml []*meta.Meta) error { - for _, m := range ml { - _, err := fmt.Fprintln(w, m.Zid.String(), m.GetTitle()) - if err != nil { - return err - } - } - return nil -} -func (*plainZettelEncoder) writeArrangement(w io.Writer, arr meta.Arrangement) error { - for key, ml := range arr { - _, err := io.WriteString(w, key) - if err != nil { - return err - } - for i, m := range ml { - if i == 0 { - _, err = io.WriteString(w, "\t") - } else { - _, err = io.WriteString(w, " ") - } - if err != nil { - return err - } - _, err = io.WriteString(w, m.Zid.String()) - if err != nil { - return err - } - } - _, err = io.WriteString(w, "\n") - if err != nil { - return err - } - } - return nil -} - -type jsonZettelEncoder struct { - sq *query.Query - getRights func(*meta.Meta) api.ZettelRights -} - -func (jze *jsonZettelEncoder) writeMetaList(w io.Writer, ml []*meta.Meta) error { + return ap.createMapMeta(key) + } + } + } + err := a.writeQueryMetaList(ctx, w, q, ml) + return content.JSON, err +} + +type actionPara struct { + w io.Writer + q *query.Query + ml []*meta.Meta + min int + max int +} + +func (ap *actionPara) createMapMeta(key string) (string, error) { + if len(ap.ml) == 0 { + return "", nil + } + arr := meta.CreateArrangement(ap.ml, key) + if len(arr) == 0 { + return "", nil + } + min, max := ap.min, ap.max + mm := make(api.MapMeta, len(arr)) + for tag, metaList := range arr { + if len(metaList) < min || (max > 0 && len(metaList) > max) { + continue + } + zidList := make([]api.ZettelID, 0, len(metaList)) + for _, m := range metaList { + zidList = append(zidList, api.ZettelID(m.Zid.String())) + } + mm[tag] = zidList + } + + err := encodeJSONData(ap.w, api.MapListJSON{Map: mm}) + return content.JSON, err +} + +func (a *API) writeQueryMetaList(ctx context.Context, w io.Writer, q *query.Query, ml []*meta.Meta) error { result := make([]api.ZidMetaJSON, 0, len(ml)) for _, m := range ml { result = append(result, api.ZidMetaJSON{ ID: api.ZettelID(m.Zid.String()), Meta: m.Map(), - Rights: jze.getRights(m), + Rights: a.getRights(ctx, m), }) } err := encodeJSONData(w, api.ZettelListJSON{ - Query: jze.sq.String(), - Human: jze.sq.Human(), + Query: q.String(), + Human: q.Human(), List: result, }) return err } -func (*jsonZettelEncoder) writeArrangement(w io.Writer, arr meta.Arrangement) error { - mm := make(api.MapMeta, len(arr)) - for key, metaList := range arr { - zidList := make([]api.ZettelID, 0, len(metaList)) - for _, m := range metaList { - zidList = append(zidList, api.ZettelID(m.Zid.String())) - } - mm[key] = zidList - } - return encodeJSONData(w, api.MapListJSON{Map: mm}) -} Index: web/adapter/api/request.go ================================================================== --- web/adapter/api/request.go +++ web/adapter/api/request.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -21,11 +21,11 @@ "zettelstore.de/z/domain/meta" "zettelstore.de/z/input" ) // getEncoding returns the data encoding selected by the caller. -func getEncoding(r *http.Request, q url.Values) (api.EncodingEnum, string) { +func getEncoding(r *http.Request, q url.Values, defEncoding api.EncodingEnum) (api.EncodingEnum, string) { encoding := q.Get(api.QueryKeyEncoding) if encoding != "" { return api.Encoder(encoding), encoding } if enc, ok := getOneEncoding(r, api.HeaderAccept); ok { @@ -32,11 +32,11 @@ return api.Encoder(enc), enc } if enc, ok := getOneEncoding(r, api.HeaderContentType); ok { return api.Encoder(enc), enc } - return api.EncoderPlain, api.EncoderPlain.String() + return defEncoding, defEncoding.String() } func getOneEncoding(r *http.Request, key string) (string, bool) { if values, ok := r.Header[key]; ok { for _, value := range values { Index: web/adapter/api/update_zettel.go ================================================================== --- web/adapter/api/update_zettel.go +++ web/adapter/api/update_zettel.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2021-2023 Detlef Stern +// Copyright (c) 2021-2022 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 @@ -11,38 +11,45 @@ package api import ( "net/http" - "zettelstore.de/c/api" - "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" ) + +// MakeUpdatePlainZettelHandler creates a new HTTP handler to update a zettel. +func (a *API) MakeUpdatePlainZettelHandler(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, err := buildZettelFromPlainData(r, zid) + if err != nil { + a.reportUsecaseError(w, adapter.NewErrBadRequest(err.Error())) + return + } + if err = updateZettel.Run(r.Context(), zettel, true); err != nil { + a.reportUsecaseError(w, err) + return + } + w.WriteHeader(http.StatusNoContent) + } +} // MakeUpdateZettelHandler creates a new HTTP handler to update a zettel. func (a *API) MakeUpdateZettelHandler(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 } - - q := r.URL.Query() - var zettel domain.Zettel - switch enc, _ := getEncoding(r, q); enc { - case api.EncoderPlain: - zettel, err = buildZettelFromPlainData(r, zid) - case api.EncoderJson: - zettel, err = buildZettelFromJSONData(r, zid) - default: - http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) - return - } - + zettel, err := buildZettelFromJSONData(r, zid) if err != nil { a.reportUsecaseError(w, adapter.NewErrBadRequest(err.Error())) return } if err = updateZettel.Run(r.Context(), zettel, true); err != nil { Index: web/adapter/request.go ================================================================== --- web/adapter/request.go +++ web/adapter/request.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -49,23 +49,15 @@ } return 0, false } // GetQuery retrieves the specified options from a query. -func GetQuery(vals url.Values) (result *query.Query) { - if exprs, found := vals[api.QueryKeyQuery]; found { - result = query.Parse(strings.Join(exprs, " ")) - } - if seeds, found := vals[api.QueryKeySeed]; found { - for _, seed := range seeds { - if si, err := strconv.ParseInt(seed, 10, 31); err == nil { - result = result.SetSeed(int(si)) - break - } - } - } - return result +func GetQuery(vals url.Values) *query.Query { + if exprs, found := vals[api.QueryKeyQuery]; found { + return query.Parse(strings.Join(exprs, " ")) + } + return nil } // GetZCDirection returns a direction value for a given string. func GetZCDirection(s string) usecase.ZettelContextDirection { switch s { Index: web/adapter/webui/create_zettel.go ================================================================== --- web/adapter/webui/create_zettel.go +++ web/adapter/webui/create_zettel.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -9,21 +9,18 @@ //----------------------------------------------------------------------------- package webui import ( - "bytes" "context" "net/http" "zettelstore.de/c/api" "zettelstore.de/z/box" "zettelstore.de/z/domain" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" - "zettelstore.de/z/encoder/zmkenc" - "zettelstore.de/z/evaluator" "zettelstore.de/z/parser" "zettelstore.de/z/usecase" "zettelstore.de/z/web/adapter" "zettelstore.de/z/web/server" ) @@ -49,25 +46,29 @@ } roleData, syntaxData := retrieveDataLists(ctx, ucListRoles, ucListSyntax) switch op { case actionCopy: - wui.renderZettelForm(ctx, w, createZettel.PrepareCopy(origZettel), "Copy Zettel", "Copy Zettel", "", roleData, syntaxData) + wui.renderZettelForm(ctx, w, createZettel.PrepareCopy(origZettel), "Copy Zettel", "Copy Zettel", roleData, syntaxData) case actionVersion: - wui.renderZettelForm(ctx, w, createZettel.PrepareVersion(origZettel), "Version Zettel", "Versionzettel", "", roleData, syntaxData) + wui.renderZettelForm(ctx, w, createZettel.PrepareVersion(origZettel), "Version Zettel", "Versionzettel", roleData, syntaxData) case actionFolge: - wui.renderZettelForm(ctx, w, createZettel.PrepareFolge(origZettel), "Folge Zettel", "Folgezettel", "", roleData, syntaxData) + wui.renderZettelForm(ctx, w, createZettel.PrepareFolge(origZettel), "Folge Zettel", "Folgezettel", roleData, syntaxData) case actionNew: m := origZettel.Meta title := parser.ParseMetadata(m.GetTitle()) textTitle, err2 := encodeInlinesText(&title, wui.gentext) if err2 != nil { wui.reportError(ctx, w, err2) return } - htmlTitle := wui.getSimpleHTMLEncoder().InlinesString(&title) - wui.renderZettelForm(ctx, w, createZettel.PrepareNew(origZettel), textTitle, htmlTitle, "", roleData, syntaxData) + htmlTitle, err2 := wui.getSimpleHTMLEncoder().InlinesString(&title) + if err2 != nil { + wui.reportError(ctx, w, err2) + return + } + wui.renderZettelForm(ctx, w, createZettel.PrepareNew(origZettel), textTitle, htmlTitle, roleData, syntaxData) } } } func retrieveDataLists(ctx context.Context, ucListRoles usecase.ListRoles, ucListSyntax usecase.ListSyntax) ([]string, []string) { @@ -88,21 +89,19 @@ func (wui *WebUI) renderZettelForm( ctx context.Context, w http.ResponseWriter, zettel domain.Zettel, title, heading string, - formActionURL string, roleData []string, syntaxData []string, ) { user := server.GetUser(ctx) m := zettel.Meta var base baseData wui.makeBaseData(ctx, wui.rtConfig.Get(ctx, m, api.KeyLang), title, "", user, &base) wui.renderTemplate(ctx, w, id.FormTemplateZid, &base, formZettelData{ Heading: heading, - FormActionURL: formActionURL, MetaTitle: m.GetDefault(api.KeyTitle, ""), MetaTags: m.GetDefault(api.KeyTags, ""), MetaRole: m.GetDefault(api.KeyRole, ""), HasRoleData: len(roleData) > 0, RoleData: roleData, @@ -142,40 +141,5 @@ } else { wui.redirectFound(w, r, wui.NewURLBuilder('h').SetZid(api.ZettelID(newZid.String()))) } } } - -// MakeGetZettelFromListHandler creates a new HTTP handler to store content of -// an existing zettel. -func (wui *WebUI) MakeGetZettelFromListHandler( - listMeta usecase.ListMeta, evaluate *usecase.Evaluate, - ucListRoles usecase.ListRoles, ucListSyntax usecase.ListSyntax) http.HandlerFunc { - - return func(w http.ResponseWriter, r *http.Request) { - q := adapter.GetQuery(r.URL.Query()) - ctx := r.Context() - metaList, err := listMeta.Run(box.NoEnrichQuery(ctx, q), q) - if err != nil { - wui.reportError(ctx, w, err) - return - } - bns := evaluate.RunBlockNode(ctx, evaluator.QueryAction(ctx, q, metaList, wui.rtConfig)) - enc := zmkenc.Create() - var zmkContent bytes.Buffer - _, err = enc.WriteBlocks(&zmkContent, &bns) - if err != nil { - wui.reportError(ctx, w, err) - return - } - - m := meta.New(id.Invalid) - m.Set(api.KeyTitle, q.Human()) - m.Set(api.KeySyntax, api.ValueSyntaxZmk) - if qval := q.String(); qval != "" { - m.Set(api.KeyQuery, qval) - } - zettel := domain.Zettel{Meta: m, Content: domain.NewContent(zmkContent.Bytes())} - roleData, syntaxData := retrieveDataLists(ctx, ucListRoles, ucListSyntax) - wui.renderZettelForm(ctx, w, zettel, "Zettel from list", "Zettel From List", wui.createNewURL, roleData, syntaxData) - } -} Index: web/adapter/webui/edit_zettel.go ================================================================== --- web/adapter/webui/edit_zettel.go +++ web/adapter/webui/edit_zettel.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -36,11 +36,11 @@ wui.reportError(ctx, w, err) return } roleData, syntaxData := retrieveDataLists(ctx, ucListRoles, ucListSyntax) - wui.renderZettelForm(ctx, w, zettel, "Edit Zettel", "Edit Zettel", "", roleData, syntaxData) + wui.renderZettelForm(ctx, w, zettel, "Edit Zettel", "Edit Zettel", roleData, syntaxData) } } // MakeEditSetZettelHandler creates a new HTTP handler to store content of // an existing zettel. Index: web/adapter/webui/forms.go ================================================================== --- web/adapter/webui/forms.go +++ web/adapter/webui/forms.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -29,11 +29,10 @@ "zettelstore.de/z/web/content" ) type formZettelData struct { Heading string - FormActionURL string MetaTitle string MetaRole string HasRoleData bool RoleData []string HasSyntaxData bool Index: web/adapter/webui/get_info.go ================================================================== --- web/adapter/webui/get_info.go +++ web/adapter/webui/get_info.go @@ -172,12 +172,12 @@ ExtLinks: extLinks, ExtNewWindow: htmlAttrNewWindow(len(extLinks) > 0), UnLinksContent: unlinkedContent, UnLinksPhrase: phrase, QueryKeyPhrase: api.QueryKeyPhrase, - EvalMatrix: wui.infoAPIMatrix(zid, false), - ParseMatrix: wui.infoAPIMatrixPlain(zid), + EvalMatrix: wui.infoAPIMatrix('v', zid), + ParseMatrix: wui.infoAPIMatrixPlain('p', zid), HasShadowLinks: len(shadowLinks) > 0, ShadowLinks: shadowLinks, Endnotes: endnotes, }) } @@ -207,56 +207,51 @@ locLinks = append(locLinks, localLink{ref.IsValid(), ref.String()}) } return locLinks, queries, extLinks } -func (wui *WebUI) infoAPIMatrix(zid id.Zid, parseOnly bool) []matrixLine { +func (wui *WebUI) infoAPIMatrix(key byte, zid id.Zid) []matrixLine { encodings := encoder.GetEncodings() encTexts := make([]string, 0, len(encodings)) for _, f := range encodings { encTexts = append(encTexts, f.String()) } sort.Strings(encTexts) + defEncoding := encoder.GetDefaultEncoding().String() parts := getParts() matrix := make([]matrixLine, 0, len(parts)) - u := wui.NewURLBuilder('z').SetZid(api.ZettelID(zid.String())) + u := wui.NewURLBuilder(key).SetZid(api.ZettelID(zid.String())) for _, part := range parts { row := make([]simpleLink, len(encTexts)) for j, enc := range encTexts { - if parseOnly { - u.AppendKVQuery(api.QueryKeyParseOnly, "") + u.AppendKVQuery(api.QueryKeyPart, part) + if enc != defEncoding { + u.AppendKVQuery(api.QueryKeyEncoding, enc) } - u.AppendKVQuery(api.QueryKeyPart, part) - u.AppendKVQuery(api.QueryKeyEncoding, enc) - row[j] = simpleLink{enc, u.AttrString()} + row[j] = simpleLink{enc, u.String()} u.ClearQuery() } matrix = append(matrix, matrixLine{part, row}) } return matrix } -func (wui *WebUI) infoAPIMatrixPlain(zid id.Zid) []matrixLine { - matrix := wui.infoAPIMatrix(zid, true) +func (wui *WebUI) infoAPIMatrixPlain(key byte, zid id.Zid) []matrixLine { + matrix := wui.infoAPIMatrix(key, zid) apiZid := api.ZettelID(zid.String()) // Append plain and JSON format u := wui.NewURLBuilder('z').SetZid(apiZid) for i, part := range getParts() { u.AppendKVQuery(api.QueryKeyPart, part) - matrix[i].Elements = append(matrix[i].Elements, simpleLink{"plain", u.AttrString()}) + matrix[i].Elements = append(matrix[i].Elements, simpleLink{"plain", u.String()}) u.ClearQuery() } - - u.AppendKVQuery(api.QueryKeyEncoding, api.EncodingJson) - u.AppendKVQuery(api.QueryKeyPart, api.PartZettel) - matrix[0].Elements = append(matrix[0].Elements, simpleLink{"json", u.AttrString()}) - - u.ClearQuery() - u.AppendKVQuery(api.QueryKeyEncoding, api.EncodingJson) - u.AppendKVQuery(api.QueryKeyPart, api.PartMeta) - matrix[1].Elements = append(matrix[1].Elements, simpleLink{"json", u.AttrString()}) + u = wui.NewURLBuilder('j').SetZid(apiZid) + matrix[0].Elements = append(matrix[0].Elements, simpleLink{"json", u.String()}) + u = wui.NewURLBuilder('m').SetZid(apiZid) + matrix[1].Elements = append(matrix[1].Elements, simpleLink{"json", u.String()}) return matrix } func getParts() []string { return []string{api.PartZettel, api.PartMeta, api.PartContent} Index: web/adapter/webui/get_zettel.go ================================================================== --- web/adapter/webui/get_zettel.go +++ web/adapter/webui/get_zettel.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -13,11 +13,10 @@ import ( "bytes" "net/http" "zettelstore.de/c/api" - "zettelstore.de/c/html" "zettelstore.de/z/ast" "zettelstore.de/z/box" "zettelstore.de/z/domain/id" "zettelstore.de/z/domain/meta" "zettelstore.de/z/encoder/textenc" @@ -63,11 +62,11 @@ } user := server.GetUser(ctx) roleText := zn.Meta.GetDefault(api.KeyRole, "") canCreate := wui.canCreate(ctx, user) getTextTitle := wui.makeGetTextTitle(createGetMetadataFunc(ctx, getMeta), evalMetadata) - extURL, hasExtURL := formatURLFromMeta(zn.Meta, api.KeyURL) + extURL, hasExtURL := zn.Meta.Get(api.KeyURL) folgeLinks := createSimpleLinks(wui.encodeZettelLinks(zn.InhMeta, api.KeyFolge, getTextTitle)) backLinks := createSimpleLinks(wui.encodeZettelLinks(zn.InhMeta, api.KeyBack, getTextTitle)) successorLinks := createSimpleLinks(wui.encodeZettelLinks(zn.InhMeta, api.KeySuccessors, getTextTitle)) apiZid := api.ZettelID(zid.String()) var base baseData @@ -129,26 +128,10 @@ SuccessorLinks: successorLinks, }) } } -func formatURLFromMeta(m *meta.Meta, key string) (string, bool) { - val, found := m.Get(key) - if !found { - return "", false - } - if found && val == "" { - return "", false - } - var buf bytes.Buffer - _, err := html.AttributeEscape(&buf, val) - if err != nil { - return "", false - } - return buf.String(), true -} - func encodeInlinesText(is *ast.InlineSlice, enc *textenc.Encoder) (string, error) { if is == nil || len(*is) == 0 { return "", nil } Index: web/adapter/webui/htmlgen.go ================================================================== --- web/adapter/webui/htmlgen.go +++ web/adapter/webui/htmlgen.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2022-2023 Detlef Stern +// Copyright (c) 2022 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 @@ -125,15 +125,15 @@ g.env.ReplaceWriter(nil) return buf.String(), g.env.GetError() } // InlinesString writes an inline slice to the writer -func (g *htmlGenerator) InlinesString(is *ast.InlineSlice) string { +func (g *htmlGenerator) InlinesString(is *ast.InlineSlice) (string, error) { if is == nil || len(*is) == 0 { - return "" + return "", nil } - return html.EvaluateInline(g.env, sexprenc.GetSexpr(is), true, false) + return html.EvaluateInline(g.env, sexprenc.GetSexpr(is), true, false), nil } func (g *htmlGenerator) generateLinkZettel(senv sxpf.Environment, args *sxpf.Pair, _ int) (sxpf.Value, error) { env := senv.(*html.EncEnvironment) if a, refValue, ok := html.PrepareLink(env, args); ok { Index: web/adapter/webui/htmlmeta.go ================================================================== --- web/adapter/webui/htmlmeta.go +++ web/adapter/webui/htmlmeta.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -117,30 +117,22 @@ wui.writeLink(w, key, tag, tag) } } func writeTimestamp(w io.Writer, ts time.Time) { - io.WriteString(w, ``) } func writeURL(w io.Writer, val string) { u, err := url.Parse(val) if err != nil { html.Escape(w, val) return } - if us := u.String(); us != "" { - io.WriteString(w, ``) - html.Escape(w, val) - io.WriteString(w, "") - } + fmt.Fprintf(w, "", u, htmlAttrNewWindow(true)) + html.Escape(w, val) + io.WriteString(w, "") } func (wui *WebUI) writeWord(w io.Writer, key, word string) { wui.writeLink(w, key, word, word) } @@ -187,7 +179,11 @@ } } func encodeZmkMetadata(value string, evalMetadata evalMetadataFunc, gen *htmlGenerator) string { is := evalMetadata(value) - return gen.InlinesString(&is) + result, err := gen.InlinesString(&is) + if err != nil { + return err.Error() + } + return result } Index: web/adapter/webui/lists.go ================================================================== --- web/adapter/webui/lists.go +++ web/adapter/webui/lists.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2020-2023 Detlef Stern +// Copyright (c) 2020-2022 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 @@ -43,11 +43,11 @@ return } if actions := q.Actions(); len(actions) > 0 { switch actions[0] { case "ATOM": - wui.renderAtom(w, q, metaList) + wui.renderAtom(ctx, w, q, metaList) return case "RSS": wui.renderRSS(ctx, w, q, metaList) return } @@ -57,37 +57,25 @@ htmlContent, err := enc.BlocksString(&bns) if err != nil { wui.reportError(ctx, w, err) return } - seed, found := q.GetSeed() - if !found { - seed = 0 - } user := server.GetUser(ctx) var base baseData wui.makeBaseData(ctx, wui.rtConfig.Get(ctx, nil, api.KeyLang), wui.rtConfig.GetSiteName(), "", user, &base) wui.renderTemplate(ctx, w, id.ListTemplateZid, &base, struct { Title string SearchURL string QueryValue string QueryKeyQuery string Content string - CanCreate bool - CreateURL string - QueryKeySeed string - Seed int }{ Title: wui.listTitleQuery(q), SearchURL: base.SearchURL, QueryValue: q.String(), QueryKeyQuery: base.QueryKeyQuery, Content: htmlContent, - CanCreate: wui.canCreate(ctx, user), - CreateURL: base.CreateNewURL, - QueryKeySeed: base.QueryKeySeed, - Seed: seed, }) } } func (wui *WebUI) renderRSS(ctx context.Context, w http.ResponseWriter, q *query.Query, ml []*meta.Meta) { @@ -107,13 +95,13 @@ if err != nil { wui.log.IfErr(err).Msg("unable to write RSS data") } } -func (wui *WebUI) renderAtom(w http.ResponseWriter, q *query.Query, ml []*meta.Meta) { +func (wui *WebUI) renderAtom(ctx context.Context, w http.ResponseWriter, q *query.Query, ml []*meta.Meta) { var atomConfig atom.Configuration - atomConfig.Setup(wui.rtConfig) + atomConfig.Setup(ctx, wui.rtConfig) if actions := q.Actions(); len(actions) > 2 && actions[1] == "TITLE" { atomConfig.Title = strings.Join(actions[2:], " ") } data := atomConfig.Marshal(q, ml) Index: web/adapter/webui/webui.go ================================================================== --- web/adapter/webui/webui.go +++ web/adapter/webui/webui.go @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2021-2023 Detlef Stern +// Copyright (c) 2021-2022 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 @@ -69,11 +69,10 @@ refreshURL string withAuth bool loginURL string logoutURL string searchURL string - createNewURL string } type webuiBox interface { CanCreateZettel(ctx context.Context) bool GetZettel(ctx context.Context, zid id.Zid) (domain.Zettel, error) @@ -111,11 +110,10 @@ refreshURL: ab.NewURLBuilder('g').AppendKVQuery("_c", "r").String(), withAuth: authz.WithAuth(), loginURL: loginoutBase.String(), logoutURL: loginoutBase.AppendKVQuery("logout", "").String(), searchURL: ab.NewURLBuilder('h').String(), - createNewURL: ab.NewURLBuilder('c').String(), } wui.observe(box.UpdateInfo{Box: mgr, Reason: box.OnReload, Zid: id.Invalid}) mgr.RegisterObserver(wui.observe) return wui } @@ -272,12 +270,10 @@ CanRefresh bool RefreshURL string NewZettelLinks simpleLinks SearchURL string QueryKeyQuery string - QueryKeySeed string - CreateNewURL string Content string FooterHTML string DebugMode bool } @@ -310,13 +306,11 @@ data.CanRefresh = wui.canRefresh(user) data.RefreshURL = wui.refreshURL data.NewZettelLinks = createSimpleLinks(wui.fetchNewTemplates(ctx, user)) data.SearchURL = wui.searchURL data.QueryKeyQuery = api.QueryKeyQuery - data.QueryKeySeed = api.QueryKeySeed - data.CreateNewURL = wui.createNewURL - data.FooterHTML = wui.calculateFooterHTML(ctx) + data.FooterHTML = wui.calculateFooterHTML(ctx, user) data.DebugMode = wui.debug } func (wui *WebUI) getSimpleHTMLEncoder() *htmlGenerator { return createGenerator(wui, "") } func (wui *WebUI) createZettelEncoder(ctx context.Context, m *meta.Meta) *htmlGenerator { @@ -325,11 +319,11 @@ // htmlAttrNewWindow returns HTML attribute string for opening a link in a new window. // If hasURL is false an empty string is returned. func htmlAttrNewWindow(hasURL bool) string { if hasURL { - return ` target="_blank" rel="noopener noreferrer"` + return " target=\"_blank\" ref=\"noopener noreferrer\"" } return "" } func (wui *WebUI) fetchNewTemplates(ctx context.Context, user *meta.Meta) (result []simpleLink) { @@ -354,31 +348,37 @@ if !wui.policy.CanRead(user, m) { continue } title := m.GetTitle() astTitle := parser.ParseMetadataNoLink(title) - menuTitle := wui.getSimpleHTMLEncoder().InlinesString(&astTitle) + menuTitle, err2 := wui.getSimpleHTMLEncoder().InlinesString(&astTitle) + if err2 != nil { + menuTitle, err2 = encodeInlinesText(&astTitle, wui.gentext) + if err2 != nil { + menuTitle = title + } + } result = append(result, simpleLink{ Text: menuTitle, URL: wui.NewURLBuilder('c').SetZid(api.ZettelID(m.Zid.String())). AppendKVQuery(queryKeyAction, valueActionNew).String(), }) } return result } -func (wui *WebUI) calculateFooterHTML(ctx context.Context) string { +func (wui *WebUI) calculateFooterHTML(ctx context.Context, user *meta.Meta) string { if footerZid, err := id.Parse(wui.rtConfig.Get(ctx, nil, config.KeyFooterZettel)); err == nil { if zn, err2 := wui.evalZettel.Run(ctx, footerZid, ""); err2 == nil { htmlEnc := encoder.Create(api.EncoderHTML) var buf bytes.Buffer if _, err2 = htmlEnc.WriteBlocks(&buf, &zn.Ast); err2 == nil { return buf.String() } } } - return "" + return wui.rtConfig.Get(ctx, nil, config.KeyFooterHTML) } func (wui *WebUI) renderTemplate( ctx context.Context, w http.ResponseWriter, Index: www/build.md ================================================================== --- www/build.md +++ www/build.md @@ -1,18 +1,14 @@ -# How to build Zettelstore +# How to build the Zettelstore ## Prerequisites You must install the following software: -* A current, supported [release of Go](https://go.dev/doc/devel/release), +* A current, supported [release of Go](https://golang.org/doc/devel/release.html), * [staticcheck](https://staticcheck.io/), -* [shadow](https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/shadow), -* [unparam](https://mvdan.cc/unparam), * [Fossil](https://fossil-scm.org/), * [Git](https://git-scm.org) (so that Go can download some dependencies). -See folder docs/development (a zettel box) for details. - ## Clone the repository Most of this is covered by the excellent Fossil [documentation](https://fossil-scm.org/home/doc/trunk/www/quickstart.wiki). 1. Create a directory to store your Fossil repositories. Let's assume, you have created $HOME/fossils. Index: www/changes.wiki ================================================================== --- www/changes.wiki +++ www/changes.wiki @@ -1,34 +1,9 @@ Change Log - -

    Changes for Version 0.11.0 (pending)

    - -

    Changes for Version 0.10.1 (2023-01-30)

    - * Show button to save a query into a zettel only when the current user has - authorization to do it. - (fix: webui) - -

    Changes for Version 0.10.0 (2023-01-24)

    - * Remove support for endpoints /j, /m, /q, /p, /v. Their functions - are merged into endpoint /z. This was announced in version 0.9.0. - Please use only client library with at least version 0.10.0 too. - (breaking: api) - * Remove support for runtime configuration key footer-html. Use - footer-zettel instead. Deprecated in version 0.9.0. - (breaking: webui) - * Save a query into a zettel to freeze it. - (major: webui) - * Allow to show all used metadata keys, linked with their occurrences and - their values. - (minor: webui) - * Mark ZJSON encoding as deprecated for v0.11.0. Please use Sexpr encoding - instead. - (deprecated) - * Some smaller bug fixes and improvements, to the software and to the - documentation. +

    Changes for Version 0.10.0 (pending)

    Changes for Version 0.9.0 (2022-12-12)

    * Remove support syntax pikchr. Although it was a nice idea to include it into Zettelstore, the implementation is too brittle (w.r.t. the Index: www/download.wiki ================================================================== --- www/download.wiki +++ www/download.wiki @@ -7,20 +7,20 @@ * 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.

    ZIP-ped Executables

    -Build: v0.10.1 (2023-01-30). +Build: v0.9.0 (2022-12-12). - * [/uv/zettelstore-0.10.1-linux-amd64.zip|Linux] (amd64) - * [/uv/zettelstore-0.10.1-linux-arm.zip|Linux] (arm6, e.g. Raspberry Pi) - * [/uv/zettelstore-0.10.1-windows-amd64.zip|Windows] (amd64) - * [/uv/zettelstore-0.10.1-darwin-amd64.zip|macOS] (amd64) - * [/uv/zettelstore-0.10.1-darwin-arm64.zip|macOS] (arm64, aka Apple silicon) + * [/uv/zettelstore-0.9.0-linux-amd64.zip|Linux] (amd64) + * [/uv/zettelstore-0.9.0-linux-arm.zip|Linux] (arm6, e.g. Raspberry Pi) + * [/uv/zettelstore-0.9.0-windows-amd64.zip|Windows] (amd64) + * [/uv/zettelstore-0.9.0-darwin-amd64.zip|macOS] (amd64) + * [/uv/zettelstore-0.9.0-darwin-arm64.zip|macOS] (arm64, aka Apple silicon) Unzip the appropriate file, install and execute Zettelstore according to the manual.

    Zettel for the manual

    As a starter, you can download the zettel for the manual -[/uv/manual-0.10.1.zip|here]. +[/uv/manual-0.9.0.zip|here]. Just unzip the contained files and put them into your zettel folder or configure a file box to read the zettel directly from the ZIP file. Index: www/index.wiki ================================================================== --- www/index.wiki +++ www/index.wiki @@ -23,17 +23,17 @@ packages may be experimental. [https://twitter.com/zettelstore|Stay] tuned …
    -

    Latest Release: 0.10.1 (2023-01-30)

    +

    Latest Release: 0.9.0 (2022-12-12)

    * [./download.wiki|Download] - * [./changes.wiki#0_10|Change summary] - * [/timeline?p=v0.10.1&bt=v0.9.0&y=ci|Check-ins for version 0.10.1], - [/vdiff?to=v0.10.1&from=v0.9.0|content diff] - * [/timeline?df=v0.10.1&y=ci|Check-ins derived from the 0.10.1 release], - [/vdiff?from=v0.10.1&to=trunk|content diff] + * [./changes.wiki#0_9|Change summary] + * [/timeline?p=v0.9.0&bt=v0.8.0&y=ci|Check-ins for version 0.9.0], + [/vdiff?to=v0.9.0&from=v0.8.0|content diff] + * [/timeline?df=v0.9.0&y=ci|Check-ins derived from the 0.9.0 release], + [/vdiff?from=v0.9.0&to=trunk|content diff] * [./plan.wiki|Limitations and planned improvements] * [/timeline?t=release|Timeline of all past releases]

    Build instructions