Skip to content

Commit

Permalink
feat: Basic notes rendering system in place
Browse files Browse the repository at this point in the history
- Added backlinks validation and parsing
- Provision of a notes.html for entry into root notes
- TODO: Fix AddfileRendere Tests

Co-authored-by: Anirudh Sudhir <anirudh.sudhir1@gmail.com>
  • Loading branch information
bwaklog and anirudhsudhir committed Apr 12, 2024
1 parent dbb2ae7 commit e974175
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/anna/anna.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ func (cmd *Cmd) VanillaRender() {
e.GenerateLinkStore()
fmt.Println(e.DeepDataMerge.LinkStore)
e.RenderNotes(helpers.SiteDataPath, templ)
e.GenerateNoteRoot(helpers.SiteDataPath, templ)
}
37 changes: 37 additions & 0 deletions pkg/engine/zettel_engine.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package engine

import (
"bytes"
"html/template"
"os"
"runtime"
"sync"

"github.com/acmpesuecc/anna/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)

Expand Down Expand Up @@ -57,6 +67,33 @@ func (e *Engine) GenerateLinkStore() {
}
}

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)
}

}

// func (z *Zettel) RetrieveNotePointer(noteTitle string) *zettel_parser.Note {
// for _, Note := range e.NotesMergedData.Notes {
// if Note.Frontmatter.Title == noteTitle {
Expand Down
10 changes: 0 additions & 10 deletions site/layout/note.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ <h1>{{ $PageData.Frontmatter.Title }}</h1>
{{ end }}
{{$PageData.Body}}
</section>
<!-- </section class="posts">
{{ range index .DeepDataMerge.LinkStore .PageURL }}
<a class="post-card">
<div class="post-card-div">
<h3> {{ .Frontmatter.Title }}</h3>
</div>
</a>
{{end}}
</section> -->
<hr />
<section class="posts">
<h3>Related Posts</h3>
Expand All @@ -52,7 +43,6 @@ <h3>Related Posts</h3>
<div class="post-card-div">
<h4>{{ .Frontmatter.Title }}</h4>
<p>{{ .Frontmatter.Description }}</p>
<p>{{ printf "%10s" .Body }}</p>
<p>{{ .Frontmatter.Date }}</p>
</div>
</a>
Expand Down
30 changes: 30 additions & 0 deletions site/layout/notes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{ define "notes-root" }}
{{$PageData := .DeepDataMerge.Notes }}
{{ template "head" .}}

<body>
{{template "header" .}}
<div class="body">
<article>
<section class="posts">
{{range $PageData }}
{{ if eq .Frontmatter.Head true }}
<a class="post-card" href="{{.CompleteURL}}">
<div class="post-card-div">
<h3>{{.Frontmatter.Title}}</h3>
<p>{{.Frontmatter.Description}}</p>
<p>{{.Frontmatter.Date}}</p>
</div>
</a>
{{ end }}
{{end}}
</section>
</article>
</div>

{{template "footer" .}}
</body>

</html>

{{ end}}

0 comments on commit e974175

Please sign in to comment.