{{ $PageData.Frontmatter.Title }}
- --
Related Posts
- {{range index .DeepDataMerge.LinkStore .PageURL }} - -{{ .Frontmatter.Title }}
-{{ .Frontmatter.Description }}
-{{ .Frontmatter.Date }}
-diff --git a/cmd/anna/anna.go b/cmd/anna/anna.go index a7b5d7f..d45b82f 100644 --- a/cmd/anna/anna.go +++ b/cmd/anna/anna.go @@ -185,7 +185,6 @@ func (cmd *Cmd) VanillaRender(siteDirPath string) { TagsMap: make(map[template.URL][]parser.TemplateData, 10), CollectionsMap: make(map[template.URL][]parser.TemplateData, 10), CollectionsSubPageLayouts: make(map[template.URL]string, 10), - Notes: make(map[template.URL]parser.Note, 10), SiteDataPath: siteDirPath, ErrorLogger: log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), RenderDrafts: cmd.RenderDrafts, @@ -199,8 +198,6 @@ func (cmd *Cmd) VanillaRender(siteDirPath string) { e.DeepDataMerge.Templates = make(map[template.URL]parser.TemplateData, 10) e.DeepDataMerge.TagsMap = make(map[template.URL][]parser.TemplateData, 10) e.DeepDataMerge.CollectionsMap = make(map[template.URL][]parser.TemplateData, 10) - e.DeepDataMerge.Notes = make(map[template.URL]parser.Note, 10) - e.DeepDataMerge.LinkStore = make(map[template.URL][]*parser.Note, 10) helper := helpers.Helper{ ErrorLogger: e.ErrorLogger, @@ -216,15 +213,11 @@ func (cmd *Cmd) VanillaRender(siteDirPath string) { templ := p.ParseLayoutFiles() - // Generate backlinks and validations for notes - p.BackLinkParser() - e.DeepDataMerge.Templates = p.Templates e.DeepDataMerge.TagsMap = p.TagsMap e.DeepDataMerge.CollectionsMap = p.CollectionsMap e.DeepDataMerge.CollectionsSubPageLayouts = p.CollectionsSubPageLayouts e.DeepDataMerge.LayoutConfig = p.LayoutConfig - e.DeepDataMerge.Notes = p.Notes // Copies the contents of the 'static/' directory to 'rendered/' helper.CopyDirectoryContents(siteDirPath+"static/", siteDirPath+"rendered/static/") @@ -248,11 +241,6 @@ func (cmd *Cmd) VanillaRender(siteDirPath string) { e.GenerateFeed() e.GenerateJSONIndex(siteDirPath) - e.GenerateLinkStore() - e.GenerateNoteJSONIdex(siteDirPath) - - e.RenderNotes(siteDirPath, templ) - e.GenerateNoteRoot(siteDirPath, templ) e.RenderUserDefinedPages(siteDirPath, templ) e.RenderTags(siteDirPath, templ) e.RenderCollections(siteDirPath, templ) diff --git a/pkg/engine/anna_engine.go b/pkg/engine/anna_engine.go index 9676b55..c5ceb8d 100644 --- a/pkg/engine/anna_engine.go +++ b/pkg/engine/anna_engine.go @@ -187,30 +187,6 @@ func (e *Engine) RenderCollections(fileOutPath string, templ *template.Template) wg.Wait() } -func (e *Engine) GenerateNoteJSONIdex(outFilePath string) { - jsonFile, err := os.Create(outFilePath + "rendered/static/noteindex.json") - if err != nil { - e.ErrorLogger.Fatal(err) - } - - defer func() { - err = jsonFile.Close() - if err != nil { - e.ErrorLogger.Fatal(err) - } - }() - - jsonMergedMarshaledData, err := json.Marshal(e.DeepDataMerge.Notes) - if err != nil { - e.ErrorLogger.Fatal(err) - } - - _, err = jsonFile.Write(jsonMergedMarshaledData) - if err != nil { - e.ErrorLogger.Fatal(err) - } -} - func (e *Engine) GenerateJSONIndex(outFilePath string) { // This function creates an index of the site for search // It extracts data from the e.Templates slice diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index b4d494e..3361ae8 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -34,12 +34,6 @@ type DeepDataMerge struct { // K-V pair storing the template layout name for a particular collection in the site CollectionsSubPageLayouts map[template.URL]string - //Stores all the notes - Notes map[template.URL]parser.Note - - //Stores the links of each note to other notes - LinkStore map[template.URL][]*parser.Note - // Stores the index generated for search functionality JSONIndex map[template.URL]JSONIndexTemplate } diff --git a/pkg/engine/zettel_engine.go b/pkg/engine/zettel_engine.go deleted file mode 100644 index 71b659f..0000000 --- a/pkg/engine/zettel_engine.go +++ /dev/null @@ -1,94 +0,0 @@ -package engine - -import ( - "bytes" - "html/template" - "os" - "runtime" - "sync" - - "github.com/anna-ssg/anna/v2/pkg/parser" -) - -type notesTemplateData struct { - DeepDataMerge DeepDataMerge - PageURL template.URL - TemplateData parser.TemplateData -} - -func (e *Engine) RenderNotes(fileOutPath string, templ *template.Template) { - // templ.Funcs(funcMap template.FuncMap) - - numCPU := runtime.NumCPU() - numTemplates := len(e.DeepDataMerge.Notes) - concurrency := numCPU * 2 // Adjust the concurrency factor based on system hardware resources - - if numTemplates < concurrency { - concurrency = numTemplates - } - - templateURLs := make([]string, 0, numTemplates) - for templateURL := range e.DeepDataMerge.Notes { - templateURLs = append(templateURLs, string(templateURL)) - } - - var wg sync.WaitGroup - semaphore := make(chan struct{}, concurrency) - - for _, url := range templateURLs { - if url == ".html" { - continue - } - - wg.Add(1) - semaphore <- struct{}{} - - go func(templateURL string) { - defer func() { - <-semaphore - wg.Done() - }() - - e.RenderPage(fileOutPath, template.URL(url), templ, "note") - }(url) - } - - wg.Wait() -} - -func (e *Engine) GenerateLinkStore() { - for url, note := range e.DeepDataMerge.Notes { - for _, linkURL := range note.LinkedNoteURLs { - linkNote, ok := e.DeepDataMerge.Notes[linkURL] - if ok { - e.DeepDataMerge.LinkStore[url] = append(e.DeepDataMerge.LinkStore[url], &linkNote) - } - } - } -} - -func (e *Engine) GenerateNoteRoot(fileOutPath string, templ *template.Template) { - var buffer bytes.Buffer - - notesTemplateData := notesTemplateData{ - DeepDataMerge: e.DeepDataMerge, - PageURL: "notes.html", - TemplateData: parser.TemplateData{ - Frontmatter: parser.Frontmatter{ - Title: "Curated Notes", - Description: "Currated heads of various zettles part of the page", - }, - }, - } - - err := templ.ExecuteTemplate(&buffer, "notes-root", notesTemplateData) - if err != nil { - e.ErrorLogger.Fatal(err) - } - - err = os.WriteFile(fileOutPath+"rendered/notes.html", buffer.Bytes(), 0666) - if err != nil { - e.ErrorLogger.Fatal(err) - } - -} diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index bc50c4f..49bd3c8 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -40,7 +40,6 @@ type Frontmatter struct { Date string `yaml:"date"` Draft bool `yaml:"draft"` JSFiles []string `yaml:"scripts"` - Type string `yaml:"type"` Description string `yaml:"description"` PreviewImage string `yaml:"previewimage"` Tags []string `yaml:"tags"` @@ -49,10 +48,6 @@ type Frontmatter struct { Collections []string `yaml:"collections"` Layout string `yaml:"layout"` CustomFields []map[string]string `yaml:"customFields"` - - // Head is specifically used for - // mentioning the head of the notes - Head bool `yaml:"head"` } // TemplateData This struct holds all of the data required to render any page of the site @@ -83,10 +78,6 @@ type Parser struct { // Stores data parsed from layout/config.yml LayoutConfig LayoutConfig - // Stores all the notes - Notes map[template.URL]Note - - // TODO: Look into the two below fields into a single one MdFilesName []string MdFilesPath []string @@ -172,34 +163,6 @@ func (p *Parser) AddFile(baseDirPath string, dirEntryPath string, frontmatter Fr } p.collectionsParser(page) - - if frontmatter.Type == "note" { - markdownContent = strings.TrimFunc(markdownContent, func(r rune) bool { - return r == '\n' || r == '\t' - }) - - // trim the content up to n characters - - if len(markdownContent) > 200 { - markdownContent = markdownContent[:200] - } - - note := Note{ - CompleteURL: template.URL(url), - Date: date, - Frontmatter: frontmatter, - Body: template.HTML(body), - MarkdownBody: markdownContent, - // preallocating the slice - LinkedNoteURLs: make([]template.URL, 0, 5), - LiveReload: p.LiveReload, - } - - p.Notes[note.CompleteURL] = note - - // NOTE: not adding the template urls of referenced ntoes - // rather, will populate it while links - } } func (p *Parser) ParseMarkdownContent(filecontent string, path string) (Frontmatter, string, string, bool) { diff --git a/pkg/parser/parser_test.go b/pkg/parser/parser_test.go index 88d91e1..9383cc0 100644 --- a/pkg/parser/parser_test.go +++ b/pkg/parser/parser_test.go @@ -176,66 +176,3 @@ func TestParseRobots(t *testing.T) { } }) } - -func TestNotesAndBacklinkParsing(t *testing.T) { - - gotParser := parser.Parser{ - Notes: make(map[template.URL]parser.Note), - ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), - } - - // creating dummy notes for testing - - gotParser.Notes["notes/test/test.md"] = parser.Note{ - CompleteURL: "notes/test/test.md", - Frontmatter: parser.Frontmatter{ - Title: "head note", - Type: "note", - Head: true, - }, - Body: "This is a [[backlink]] here", - } - - gotParser.Notes["notes/test/backlink.md"] = parser.Note{ - CompleteURL: "notes/test/backlink.md", - Frontmatter: parser.Frontmatter{ - Title: "backlink", - Type: "note", - }, - Body: "Content of note.", - } - - t.Run("testing notes and backlink parsing", func(t *testing.T) { - - gotParser.ParseBacklink("notes/test/test.md") - - wantParser := parser.Parser{ - Notes: map[template.URL]parser.Note{ - "notes/test/test.md": { - CompleteURL: template.URL("notes/test/test.md"), - Frontmatter: parser.Frontmatter{ - Title: "head note", - Type: "note", - Head: true, - }, - Body: template.HTML("This is a backlink here"), - LinkedNoteURLs: []template.URL{"notes/test/backlink.md"}, - }, - - "notes/test/backlink.md": { - CompleteURL: template.URL("notes/test/backlink.md"), - Frontmatter: parser.Frontmatter{ - Title: "backlink", - Type: "note", - }, - Body: template.HTML("Content of note."), - }, - }, - ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), - } - - if !reflect.DeepEqual(gotParser.Notes, wantParser.Notes) { - t.Errorf("got %v,\n want %v", gotParser.Notes, wantParser.Notes) - } - }) -} diff --git a/pkg/parser/zettel_parser.go b/pkg/parser/zettel_parser.go deleted file mode 100644 index 4cb4cb9..0000000 --- a/pkg/parser/zettel_parser.go +++ /dev/null @@ -1,125 +0,0 @@ -package parser - -import ( - "errors" - "fmt" - "html/template" - "regexp" - "runtime" - "strings" - "sync" -) - -type Note struct { - CompleteURL template.URL - Date int64 - Frontmatter Frontmatter - Body template.HTML - MarkdownBody string - LinkedNoteURLs []template.URL - LiveReload bool -} - -var backlinkRE = regexp.MustCompile(`\[[^\]]*\]\]`) - -// TODO: The current regex will search for all types of callouts of -// [[]] in the body of the markdown. The disadvantage is that it will -// not be able to ignore the callouts mentioned inside code blocks -// on inline code blocks. -// -// Change the current method with which these are parsed such that -// this edge cases is handled correctly. - -func (p *Parser) BackLinkParser() { - /* - This function is going to validate whether all the - references in the notes have a valid link to another - note - - Example: for `[Nunc ullamcorper]]` to be - a valid reference, the title part of the frontmatter - of the note `/note/1234.md` must have "Nunc ullamcorper" - */ - - numCPU := runtime.NumCPU() - numNotes := len(p.Notes) - concurrency := numCPU * 2 - - if numNotes < concurrency { - concurrency = numNotes - } - - noteURLS := make([]string, 0, numNotes) - for noteURL := range p.Notes { - noteURLS = append(noteURLS, string(noteURL)) - } - - var wg sync.WaitGroup - semaphore := make(chan struct{}, concurrency) - - for _, url := range noteURLS { - if url == ".html" { - continue - } - - wg.Add(1) - semaphore <- struct{}{} - - go func(noteURL string) { - defer func() { - <-semaphore - wg.Done() - }() - - p.ParseBacklink(template.URL(noteURL)) - }(url) - - wg.Wait() - } -} - -func (p *Parser) ParseBacklink(noteURL template.URL) { - note := p.Notes[noteURL] - noteBody := string(note.Body) // template.HTML -> string - - backlinks := backlinkRE.FindAllString(noteBody, -1) - - for _, backlink := range backlinks { - // Now that we have the backlinks to titles, - // we need to walk the notes dir to find if there - // are any matches - noteTitle := strings.Trim(backlink, "[]") - - referenceCompleteURL, err := p.ValidateBackLink(noteTitle) - if err != nil { - p.ErrorLogger.Fatal(err) - } else { - // creating anchor tag reference for parsed markdown - anchorReference := fmt.Sprintf(`%s`, referenceCompleteURL, noteTitle) - noteBody = strings.ReplaceAll(noteBody, backlink, anchorReference) - - note.LinkedNoteURLs = append(note.LinkedNoteURLs, referenceCompleteURL) - } - } - - p.Notes[noteURL] = Note{ - CompleteURL: note.CompleteURL, - Date: note.Date, - Frontmatter: note.Frontmatter, - Body: template.HTML(noteBody), - MarkdownBody: note.MarkdownBody, - LinkedNoteURLs: note.LinkedNoteURLs, - } -} - -func (p *Parser) ValidateBackLink(noteTitle string) (template.URL, error) { - for _, note := range p.Notes { - if note.Frontmatter.Title == noteTitle { - // fmt.Println("URL: ", note.CompleteURL) - return note.CompleteURL, nil - } - } - - errorMessage := fmt.Sprintf("ERR: Failed to find a note for backlink %s\n", noteTitle) - return "", errors.New(errorMessage) -} diff --git a/site/content/docs.md b/site/content/docs.md index 71b5fd4..175ac88 100644 --- a/site/content/docs.md +++ b/site/content/docs.md @@ -36,9 +36,6 @@ site1 ├── content │ ├── docs.md │ ├── index.md* -│ ├── notes -│ │ └── anna -│ │ └── zettelkasten.md │ ├── sub0folder │ │ ├── bench.md │ │ ├── building-anna @@ -54,8 +51,6 @@ site1 │ ├── collection-subpage.html* │ ├── collections.html* │ ├── config.yml* -│ ├── note.html* -│ ├── notes.html* │ ├── page.html* │ ├── partials │ │ ├── head.html @@ -93,7 +88,6 @@ Anna must be run from the parent of the site/ dir - The markdown content for the site is stored in `content/`. It can contain subdirectories along with images as the folder is recursively rendered. - The contents of this dir is rendered to the root of `rendered/` - - The `notes/` folder holds markdown notes which are rendered by a different process and include various note-specific features - Static assets such as fonts are stored in `static/` - Scripts are stored in the `scripts/` dir in `static/` - The layout of the site is configured using html files in `layout/` @@ -131,8 +125,6 @@ The `{{.PageURL}}` is of the form `index.html`, `collections/tech/go.html` and s - `{{.DeepDataMerge.CollectionsMap}}` - A map that stores a slice of templates of all pages for a particular collection url - `{{.DeepDataMerge.JSONIndex}}` - Stores the JSON index generated for a particular site (primarily used for search and graphing of tags) - `{{.DeepDataMerge.LayoutConfig}}` - Stores the layout parsed from `config.yml` -- `{{.DeepDataMerge.LinkStore}}` - Stores a map which contains a slice of pointers to the _linked notes_. -- `{{.DeepDataMerge.Notes}}` - Stores a slice of the template data of all notes - `{{.DeepDataMerge.Templates}}` - A map that stores the template data of all the pages of the site for the particular url(the URL is the PageURL for the speicified page) - `{{.DeepDataMerge.Tags}}` - A map that stores the template data of the tag sub-pages for a particular tag url - `{{.DeepDataMerge.TagsMap}}` - A map that stores a slice of templates of all pages for a particular tag url @@ -193,16 +185,12 @@ anna will throw an error if a page does not contain frontmatter or if the `title - `date`: The date of the current page - `description`: Stores the description of the current post previewed in html layouts - `draft`: When set to 'true', the current page is not rendered unless the '-d' flag is used -- `head`: Users need to manually specify head of the zettel in the frontmatter. Only head notes will be a part of `notes.html` - `layout`: Stores the layout file (\*.html) to be used to render the current page - `previewimage`: Stores the preview image of the current page - `scripts`: Stores the page-level scripts to be added - `tags`: Stores the tags of the particular page - `title` : The title of the current page - `toc`: When set to 'true', a table of contents is rendered for the current page -- `type`: - - Sets the type of the page - - Use type `note` for notes --- @@ -270,7 +258,6 @@ navbar: - Dev Guide: developer-guide.html - Tags: tags.html - Collections: collections.html - - Notes: notes.html - Posts: collections/posts.html - Anna Blog: posts/building-anna/index.html @@ -296,28 +283,3 @@ collectionLayouts: ``` --- - -## Notes - -Anna provides users with functionality of maintaining notes and sharing them. Notes opens another set of functionality for anna. Users can create under the `site/notes` directory. Besides similar use cases as a post, notes can be short snippets of information, code or even some kind of list that the users want. It supports some important aspects of [zettelkasten](https://zettelkasten.de/overview/) where users can link notes to each other, and organise similar pages in a zettel. - -We aren't trying to re-invent the process of making an editor that helps users maintain these zettels as there are already some fantastic applications, namely [Obsidian](https://obsidian.md/), [Ginko Writer](https://app.gingkowriter.com) and [Evergreen Notes](https://evergreennotes.com/). Our application as a rather needs to provide a generator to stitch these notes together to make it accessible on the site. - -### Notes directory structure - -```text -/notes -├── /zettel A -└── /zettel B - ├── note A - ├── note B - └── note C -``` - -### Linking Notes - -Notes can be linked by using callouts in markdown files such as `[[]]`. The parser will validate these links during the runtime. It checks whether there are existing valid notes with a title matching the content of the callout. If not an error is thrown and you wont be able to compile the site. - -For example. If you have a note with the title `Note A` and you would like to reference it else where in another note (could even be part of another zettel). Then `[[Note A]]` would be the appropriate callout to use it. - ---- diff --git a/site/content/notes/anna/atomicity.md b/site/content/notes/anna/atomicity.md deleted file mode 100644 index 5f1b652..0000000 --- a/site/content/notes/anna/atomicity.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -title: Created notes should be atomic -type: note -date: 2024-03-15 ---- - -Concepts that are related must be put together in a single note, and limit the content to a single concept. Capture all the relevant ideas within that note. It makes it easier to form connections, and helps better in memoisation, or while revising. - -> "If your notes are too fragmented, you’ll also fragment your link network, which may make it harder to see certain connections." - [Andy Matuschak](https://notes.andymatuschak.org/Evergreen_notes_should_be_atomic) diff --git a/site/content/notes/anna/linking.md b/site/content/notes/anna/linking.md deleted file mode 100644 index 014b82b..0000000 --- a/site/content/notes/anna/linking.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: linking notes provides a more meaningful based searching system -type: note -date: 2024-04-15 ---- - -Linking notes is more meaningful while maintaining notes. - -> "Full-text search on its own provides not enough information. Connections will do, especially in the long run." - [Christian @ Zettelkasten.de](https://zettelkasten.de/overview/) - -Providing links to these notes, and tracing them back grows your memory on the topic. It will create connections which help building memoisation. \ No newline at end of file diff --git a/site/content/notes/anna/zettelkasten.md b/site/content/notes/anna/zettelkasten.md deleted file mode 100644 index 1183362..0000000 --- a/site/content/notes/anna/zettelkasten.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: Zettelkasten with anna -description: A basic introduction to Zettelkasten and how you can share your notes with Anna. -type: note -date: 2024-03-15 -head: true ---- - -A Zettelkasten or card file consists of small items of information stored on zettels, paper slips or cards, that may be linked to each other through subject headings or other metadata such as numbers and tags. Anna now provides users with the capability of maintaining notes with back-links that helps users make use of zettelkasten. And with Deep Data Merge, you can now link all notes in almost any other file. As of now, you are limited to use these special back-links only in the notes. - -Zettelkasten suggests that [[Created notes should be atomic]]. These atomic notes can be stitched together with back-links added using a double `[]` bracket surrounding the title. Rather than using a search based method, [[linking notes provides a more meaningful based searching system]] growing memory. diff --git a/site/content/posts/building-anna/zettel_impl.md b/site/content/posts/building-anna/zettel_impl.md index f40c7a5..02ac6f1 100644 --- a/site/content/posts/building-anna/zettel_impl.md +++ b/site/content/posts/building-anna/zettel_impl.md @@ -5,7 +5,7 @@ authors: - Aditya Hegde - Anirudh Sudhir date: 2024-04-10 -draft: false +draft: true tags: - blog - tech diff --git a/site/layout/config.yml b/site/layout/config.yml index f5ffd62..8ab6eb0 100644 --- a/site/layout/config.yml +++ b/site/layout/config.yml @@ -5,7 +5,6 @@ navbar: - Dev Guide: developer-guide.html - Tags: tags.html - Collections: collections.html - - Notes: notes.html - Posts: collections/posts.html - Anna Blog: posts/building-anna/index.html baseURL: https://anna-docs.netlify.app diff --git a/site/layout/note.html b/site/layout/note.html deleted file mode 100644 index 9bf1160..0000000 --- a/site/layout/note.html +++ /dev/null @@ -1,56 +0,0 @@ -{{ define "note"}} -{{$PageData := index .DeepDataMerge.Notes .PageURL}} -{{ template "head" .}} - -
- - {{template "header" .}} -{{ .Frontmatter.Description }}
-{{ .Frontmatter.Date }}
-