Add hero feature on articles

This commit is contained in:
Evrard Van Espen
2025-11-14 13:59:46 +00:00
parent 1ba79a05df
commit c399a7dc56

View File

@@ -21,6 +21,7 @@ import (
// - posts: A slice of Post structs representing the blog posts. // - posts: A slice of Post structs representing the blog posts.
// - tags: A slice of strings representing the tags. // - tags: A slice of strings representing the tags.
// - css: A string containing the compiled CSS styles. // - css: A string containing the compiled CSS styles.
//
// Returns: // Returns:
// - An error if any step of the process fails, otherwise nil. // - An error if any step of the process fails, otherwise nil.
func renderHome(posts []Post, tags []string, css string) error { func renderHome(posts []Post, tags []string, css string) error {
@@ -82,6 +83,7 @@ func renderHome(posts []Post, tags []string, css string) error {
// - lang: The programming language of the code. // - lang: The programming language of the code.
// - inline: Whether the code block is inline or not. // - inline: Whether the code block is inline or not.
// - params: Additional parameters for highlighting, such as highlighted lines. // - params: Additional parameters for highlighting, such as highlighted lines.
//
// Returns: // Returns:
// - A string containing the highlighted code block in HTML format. // - A string containing the highlighted code block in HTML format.
func highlightCodeBlock(source, lang string, inline bool, params map[string]string) string { func highlightCodeBlock(source, lang string, inline bool, params map[string]string) string {
@@ -113,6 +115,7 @@ func highlightCodeBlock(source, lang string, inline bool, params map[string]stri
// - post: The Post struct representing the blog post. // - post: The Post struct representing the blog post.
// - css: A string containing the compiled CSS styles. // - css: A string containing the compiled CSS styles.
// - tags: A slice of strings representing the tags. // - tags: A slice of strings representing the tags.
//
// Returns: // Returns:
// - An error if any step of the process fails, otherwise nil. // - An error if any step of the process fails, otherwise nil.
func renderPost(post Post, css string, tags []string) error { func renderPost(post Post, css string, tags []string) error {
@@ -142,7 +145,7 @@ func renderPost(post Post, css string, tags []string) error {
} }
hero := func(post Post) template.HTML { hero := func(post Post) template.HTML {
if post.Hero != "" { if post.Hero != "/medias/" && post.Hero != "/medias/none" {
return template.HTML(fmt.Sprintf("<img id=\"hero\" src=\"%s\"/>", post.Hero)) return template.HTML(fmt.Sprintf("<img id=\"hero\" src=\"%s\"/>", post.Hero))
} else { } else {
return template.HTML("") return template.HTML("")
@@ -190,6 +193,7 @@ func renderPost(post Post, css string, tags []string) error {
// - posts: A slice of Post structs representing the blog posts associated with the tag. // - posts: A slice of Post structs representing the blog posts associated with the tag.
// - tags: A slice of strings representing all tags. // - tags: A slice of strings representing all tags.
// - css: A string containing the compiled CSS styles. // - css: A string containing the compiled CSS styles.
//
// Returns: // Returns:
// - An error if any step of the process fails, otherwise nil. // - An error if any step of the process fails, otherwise nil.
func renderTagPage(tag string, posts []Post, tags []string, css string) error { func renderTagPage(tag string, posts []Post, tags []string, css string) error {