From de1248a965dde796cbf831c3f5cab17274c679c9 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Mon, 8 Aug 2022 15:27:30 +0100 Subject: [PATCH] Added Readme Signed-off-by: Marcus Noble --- data.yaml | 59 +++++++++++++++++++++++++------------------------- main.go | 28 ++++++++++++++++-------- src/README.md | 32 +++++++++++++++++++++++++++ src/index.html | 3 ++- 4 files changed, 83 insertions(+), 39 deletions(-) create mode 100644 src/README.md diff --git a/data.yaml b/data.yaml index e8f2baf..00006a9 100644 --- a/data.yaml +++ b/data.yaml @@ -5,75 +5,76 @@ social: - url: https://marcusnoble.co.uk slug: "/blog" title: My articles on my Blog - content: | - + name: Blog + icon: | + - Blog - url: "mailto:hello@marcusnoble.co.uk" slug: "" title: Email me - content: | - - Email + name: Email + icon: | + - url: https://cv.marcusnoble.co.uk slug: "/cv" title: My CV - content: | - - C.V. + name: C.V. + icon: | + - url: https://www.github.com/AverageMarcus slug: "/github" title: AverageMarcus on GitHub - content: | - - GitHub + name: GitHub + icon: | + - url: https://twitter.com/Marcus_Noble_ slug: "/twitter" title: "@Marcus_Noble_ on Twitter" - content: | - - Twitter + name: Twitter + icon: | + - url: https://k8s.social/@Marcus slug: "/mastodon" title: "@marcus@k8s.social on Mastodon" - content: | + name: Mastodon + icon: | - Mastodon - url: https://www.linkedin.com/in/marcusnoble/ slug: "/linkedin" title: Connect with me on Linkedin - content: | - + name: LinkedIn + icon: | + - LinkedIn - url: https://noti.st/averagemarcus slug: "/notist" title: View my previous talks on Notist - content: | - + name: Notist + icon: | + - Notist - url: https://youtube.com/playlist?list=PLT41C0Ggz5wa66-AU5xapbOuzkUKUPLzi slug: "/youtube" title: My appearances on YouTube - content: | - - YouTube + name: YouTube + icon: | + - url: https://name.pn/marcus-noble slug: "/pronouns" title: More about my name and pronouns - content: | - - name.pn + name: name.pn + icon: | + + projects: - url: https://github.com/AverageMarcus/kube-image-prefetch name: kube-image-prefetch diff --git a/main.go b/main.go index 9298f72..ee07152 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "os" + "path" "strings" "gopkg.in/yaml.v2" @@ -42,28 +43,37 @@ func main() { } } + funcMap := template.FuncMap(map[string]interface{}{ + "join": func(objs []interface{}, key, joiner string) template.HTML { + vals := []string{} + for _, obj := range objs { + val := obj.(map[interface{}]interface{})[key] + vals = append(vals, val.(string)) + } + return template.HTML(strings.Join(vals, joiner)) + }, + "html": func(str string) template.HTML { + return template.HTML(str) + }, + }) + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { page := "src" + r.URL.Path if strings.HasSuffix(page, "/") { page = page + "index.html" } - if strings.HasSuffix(page, ".html") { - tpl, err := template.ParseFS(res, page) + if strings.HasSuffix(page, ".html") || strings.HasSuffix(page, ".md") { + tpl, err := template.New(path.Base(page)).Funcs(funcMap).ParseFS(res, page) if err != nil { log.Printf("page %s (%s) not found...", r.RequestURI, page) + log.Println(err) w.WriteHeader(http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) - - tpl.Funcs(template.FuncMap(map[string]interface{}{ - "html": func(str string) template.HTML { - return template.HTML(str) - }, - })) - if err := tpl.Execute(w, data); err != nil { + log.Println(err) return } } else { diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..1ff1350 --- /dev/null +++ b/src/README.md @@ -0,0 +1,32 @@ +
+ +# Hi 👋, I'm Marcus + +**Pronounced:** /ˈmɑːkəs/ ⚡️ **Pronouns:** He/Him/His + +{{ .intro | html }} + +## 🌐 Find me around the web + +| {{ range .social }}{{ .name | html }} | {{ end }} + +## 💻 My Open Source Projects + +All my Open Source projects can be find on my GitHub profile (as well as my personal Gitea instance, GitLab, Codeberg and BitBucket). + +Below are a selection of highlights. + +{{ range .projects }} +[**{{ .name }}**]({{ .url }}) - {{ .description }} [{{ join .languages "name" ", " }}] +{{ end }} + +## 🗓 Upcoming Events + +{{ range .events }} +{{ .humanDate }} - [**{{.eventName}}**]({{ .url }}) +{{ range .details }} +`{{ .name }} - {{ .type }}` +{{ end }} +{{- end }} + +
diff --git a/src/index.html b/src/index.html index a88a567..77daba9 100644 --- a/src/index.html +++ b/src/index.html @@ -261,7 +261,8 @@ {{ range .social }}
  • - {{ .content | html }} + {{ .icon | html }} + {{ .name }}
  • {{ end }}