Added blog posts, and improved homepage
This commit is contained in:
12
blog/init.go
Normal file
12
blog/init.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package blog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func InitHttpHandlers() {
|
||||
prefix := "/blog/"
|
||||
http.HandleFunc(fmt.Sprint(prefix, "{$}"), blogTop)
|
||||
http.HandleFunc(fmt.Sprint(prefix, "{slug}/"), showPost)
|
||||
}
|
57
blog/postBuilder.go
Normal file
57
blog/postBuilder.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package blog
|
||||
|
||||
import (
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
"html/template"
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
func makePost(markdownContent []byte) Post {
|
||||
headerRegex := regexp.MustCompile(`(?ms)^---\n.*?---`)
|
||||
header := headerRegex.Find(markdownContent)
|
||||
headerKeysRegex := regexp.MustCompile(`(?m)^(\w+): ([^\n]*)$`)
|
||||
headerKeys := headerKeysRegex.FindAllSubmatch(header, -1)
|
||||
postBody := headerRegex.ReplaceAll(markdownContent, []byte(""))
|
||||
|
||||
post := Post{}
|
||||
|
||||
for _, headerKey := range headerKeys {
|
||||
key, value := string(headerKey[1]), string(headerKey[2])
|
||||
switch key {
|
||||
case "title":
|
||||
post.Title = value
|
||||
case "date":
|
||||
date, err := time.Parse(time.DateOnly, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
post.Date = date
|
||||
case "updatedDate":
|
||||
date, err := time.Parse(time.DateOnly, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
post.UpdatedDate = date
|
||||
case "author":
|
||||
post.Author = value
|
||||
case "slug":
|
||||
post.Slug = value
|
||||
}
|
||||
}
|
||||
|
||||
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
|
||||
p := parser.NewWithExtensions(extensions)
|
||||
doc := p.Parse(postBody)
|
||||
|
||||
// create HTML renderer with extensions
|
||||
htmlFlags := html.CommonFlags | html.HrefTargetBlank
|
||||
opts := html.RendererOptions{Flags: htmlFlags}
|
||||
renderer := html.NewRenderer(opts)
|
||||
|
||||
post.Body = template.HTML(markdown.Render(doc, renderer))
|
||||
|
||||
return post
|
||||
}
|
87
blog/posts.go
Normal file
87
blog/posts.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package blog
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"prettysunflower-website/baseTemplates"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
Slug string
|
||||
Title string
|
||||
Author string
|
||||
Date time.Time
|
||||
UpdatedDate time.Time
|
||||
Body template.HTML
|
||||
}
|
||||
|
||||
//go:embed posts/*
|
||||
var postsFS embed.FS
|
||||
|
||||
func getAllPosts() []Post {
|
||||
postsDir, err := postsFS.ReadDir("posts")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var posts []Post
|
||||
|
||||
for _, postFileName := range postsDir {
|
||||
post, err := postsFS.ReadFile(fmt.Sprint("posts/", postFileName.Name()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
posts = append(posts, makePost(post))
|
||||
}
|
||||
|
||||
//fmt.Println(posts[0].UpdatedDate.IsZero())
|
||||
return posts
|
||||
}
|
||||
|
||||
type PostListTemplateData struct {
|
||||
Posts []Post
|
||||
}
|
||||
|
||||
func blogTop(w http.ResponseWriter, r *http.Request) {
|
||||
posts := getAllPosts()
|
||||
templateData := PostListTemplateData{
|
||||
Posts: posts,
|
||||
}
|
||||
|
||||
tmpl := template.Must(template.ParseFS(baseTemplates.FS, "templates/base.tmpl", "templates/blog/postsList.tmpl"))
|
||||
|
||||
err := tmpl.ExecuteTemplate(w, "base", templateData)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func showPost(w http.ResponseWriter, r *http.Request) {
|
||||
slug := r.PathValue("slug")
|
||||
posts := getAllPosts()
|
||||
postIndex, found := sort.Find(len(posts), func(i int) int {
|
||||
return strings.Compare(slug, posts[i].Slug)
|
||||
})
|
||||
|
||||
if !found {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
post := posts[postIndex]
|
||||
|
||||
tmpl := template.Must(template.ParseFS(baseTemplates.FS, "templates/base.tmpl", "templates/blog/blogPost.tmpl"))
|
||||
|
||||
err := tmpl.ExecuteTemplate(w, "base", post)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
37
blog/posts/2024-06-08-pride-flag-geneva.md
Normal file
37
blog/posts/2024-06-08-pride-flag-geneva.md
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
title: Le Progress Pride flag de Genève
|
||||
date: 2024-06-08
|
||||
updatedDate: 2024-06-20
|
||||
author: Remilia
|
||||
slug: pride-flag-geneve
|
||||
---
|
||||
|
||||
Cette année, lors de la journée internationale contre l'homophobie, la transphobie et la biphobie,
|
||||
le pont du Mont-Blanc à Genève avait ces drapeaux de déployés, une version modifiée du Progress Pride flag
|
||||
que je trouve absolument magnifique
|
||||
|
||||

|
||||
|
||||
Pour avoir plus d'informations à propos de ce drapeau, j'ai contacté la ville de Genève,
|
||||
qui m'a répondu par courriel: ce drapeau a apparemment été créé en 2020 spécialement pour la Ville de Genève,
|
||||
par une personne qui souhaite rester anonyme, pour les pavoisements du Pont du Mont-Blanc et du Palais Anna et
|
||||
Jean-Gabriel Eynard. Il a été introduit en 2021 lors de la campagne Ma vie, ma ville, mes couleurs.
|
||||
|
||||
Il existe aussi des versions verticales de ce drapeau, qui sont notamment utilisées à d'autres endroits
|
||||
comme la gare Cornavin ou la Place de Neuve.
|
||||
|
||||
Les raisons pour la création de ce nouveau drapeau, selon la Ville, étaient qu'elle « souhaitait pouvoir
|
||||
bénéficier de supports plus inclusifs et représentatifs de la diversité des communautés LGBTIQ+ tout en
|
||||
répondant aux contraintes techniques spécifiques à ce type de pavoisement ».
|
||||
|
||||
Étant donné que je ne trouve pas de versions de ce drapeau hors des photos, j'ai recréé ce drapeau dans Sketch,
|
||||
si vous souhaitez désormais l'utiliser.
|
||||
|
||||
<p style="text-align: center">
|
||||
<img src="https://www.remilia.ch/progress-flag/progress_flag.svg" alt="Geneva's progress flag image" style="width: 50%; margin-left: auto; margin-right: auto"/>
|
||||
</p>
|
||||
|
||||
Veuillez noter que selon la Ville, « l'utilisation de ce design, réalisé sur commande par une personne concernée
|
||||
qui a souhaité rester anonyme, est libre de droits, sous réserve de mention de son origine. »
|
||||
Veuillez donc créditer correctement la personne qui a créé ce design si vous souhaitez l'utiliser ^^
|
||||
(et non, ce n'est pas moi 🙃).
|
Reference in New Issue
Block a user