From 6d733e0024f082958c52e3dcde984147a1d7eea5 Mon Sep 17 00:00:00 2001 From: Jacob Hartmann Date: Thu, 9 Jun 2022 20:26:01 +0200 Subject: [PATCH] refactored blog and redesigned it --- css/style.css | 36 ++++++------- main.go | 37 ++++++++++--- postUtils.go | 117 ++++++++++++++++++++++++++++++++++++------ templates/blog.tmpl | 41 ++------------- templates/main.tmpl | 17 ++++++ templates/navbar.tmpl | 12 +++++ templates/past.tmpl | 29 +++++++---- templates/title.tmpl | 14 +++++ 8 files changed, 213 insertions(+), 90 deletions(-) create mode 100644 templates/main.tmpl create mode 100644 templates/navbar.tmpl create mode 100644 templates/title.tmpl diff --git a/css/style.css b/css/style.css index 2463d5e..1ccead4 100644 --- a/css/style.css +++ b/css/style.css @@ -1,23 +1,19 @@ {{define "style"}} html, body { - color: LightGrey; font-family: 'HelveticaNeue-Light','Helvetica Neue', Helvetica, Arial, sans-serif;; font-size: 15px; line-height: 170%; - //color: #35465D; color: #506692; background-color: #d6e2fa; - //background-color: #506692; } + .title { - //padding: 20px; justify-content: flex-end; color: #ff8f00; } .title:hover { - //background-color: #687fad; color: lightblue; background-color: #d6e2fa; } @@ -43,8 +39,6 @@ article { } .posts{ - //width: 700px; - //background-color: #506692; background-color: #d6e2fa; } @@ -62,7 +56,6 @@ h1 { letter-spacing: 5px; margin-right: -5px; font-size: 40px; - //color: #97c5e0; color: #506692; text-align: right; justify-content: flex-end; @@ -81,11 +74,9 @@ a { a:hover { color: orange; - --background-color: #ffffff; } img { - //border-radius: 10px; display: block; width: 100%; max-width: 600px; @@ -106,7 +97,6 @@ ul { .tagline{ text-align: right; color: #506692; - //color: #97c5e0; } .section{ @@ -121,6 +111,7 @@ ul { justify-content: flex-end; padding-bottom: 20px; color: #35465D; + width: 270px } .menuselect{ @@ -136,7 +127,6 @@ ul { } .menuElement:hover { - //background-color: #687fad; color: lightblue; } @@ -153,15 +143,24 @@ ul { text-decoration: none; } -.bottomMenuElement:hover { - //background-color: #ffffff; - //color: lightblue; - //background-color: #d6e2fa; +.shit { + padding: 32px; +} + + + +#yearline li.yearline { + padding-bottom: 8px; +} + +#yearline li.yearend { + height: 24px; } .titleArea { display: flex; justify-content: center; + margin-bottom:30px; } #titleArea ul>li { @@ -170,13 +169,13 @@ ul { #titleArea li { display: table-cell; + width: 270px; } #section ul > li{ display: block; margin: auto; float: center; - //text-align: right; list-style: none; } @@ -187,7 +186,6 @@ ul { } #menu ul{ - //display: block; margin: auto; float: center; text-align: center; @@ -198,6 +196,4 @@ ul { //display: inline-block; } - - {{end}} diff --git a/main.go b/main.go index 228e328..2fd6afa 100644 --- a/main.go +++ b/main.go @@ -9,9 +9,10 @@ import ( "strings" ) -//Page : Is exported to PostCollection type Page struct { Title string + Years [][]Post + //Years map[int][]Post Posts []Post CurrentPage string } @@ -19,13 +20,27 @@ type Page struct { var style = `` var name = "takunomi" var posts []Post -var templates = template.Must(template.ParseFiles("templates/blog.tmpl", "templates/about.tmpl","templates/keru_shoujo.tmpl", "templates/past.tmpl", "templates/contact.tmpl", "templates/blog_roll.tmpl", "templates/post.tmpl")) +var years [][]Post +//var years map[int][]Post +var templates = template.Must(template.ParseFiles( + "templates/blog.tmpl", + "templates/about.tmpl", + "templates/keru_shoujo.tmpl", + "templates/past.tmpl", + "templates/contact.tmpl", + "templates/blog_roll.tmpl", + "templates/title.tmpl", + "templates/navbar.tmpl", + "templates/main.tmpl", + "templates/post.tmpl")) func main() { buildHandlers() retrievePosts() + + if os.Args[1] == "local" { http.ListenAndServe(":8080", nil) } @@ -38,8 +53,14 @@ func main() { func retrievePosts() { posts = nil + years = nil + //years = make(map[int][]Post) filepath.Walk("./posts", newPost) - posts = reversePosts() + years = reverseYears() + for i := 0; i years[i][0].Year { //Is this year greater? + fmt.Println("older") + if i == len(years) - 1 { // Is this the final element? + fmt.Println("oldest") + y := append(years, []Post{p}) // then append a new year + years = y + break + } else if years[i+1][0].Year > p.Year{ // Is the next year greater than the post's year? + fmt.Println("Inbetween") + // Insert a new year in between + years = append(years[:i+2], years[i+1:]...) + //years = append(years[:i+1], years[i:]...) + years[i+1] = []Post{p} + break + } + } + } + } + fmt.Println("") + + /* + var finalYearExist := years[len(years)] != nil + var postIsNewest := years[len(years)][0].Date.Year() < p.Date.Year() + if finalYearsExist && postIsNewest { //is the year of this post greater than the year of the posts at the final slice? + var newYear := []Post{p} // Then add a nice slice with this post as an element + years = append(years, newYear) + } else { + var yearExists := false + for i := 0; i < len(years); i++ { //go through each year + if p.Date.Year() == years[i][0].Date.Year() { //found the year + yearExists = true + years = append(years[i], p) //add the post to the year + break + } + } + if yearExists == false { + } + } + aYear := years[0] + yearPosts := years[p.Date.Year()] + yearPosts = append(yearPosts, p) + //yearPosts = insertPostAccordingToDate(p, yearPosts) + years[p.Date.Year()] = yearPosts + posts = insertPostAccordingToDate(p, posts) + */ return nil } @@ -74,34 +146,49 @@ func getDate(n *html.Node) time.Time { return t } -func reversePosts() []Post { - length := len(posts) +func reverseYears() [][]Post { + length := len(years) + s := make([][]Post, length) + for i := 0; i < length; i++ { + s[i] = years[length-(i+1)] } + return s +} + +func reversePosts(slice []Post) []Post { + length := len(slice) s := make([]Post, length) for i := 0; i < length; i++ { - s[i] = posts[length-(i+1)] + s[i] = slice[length-(i+1)] } return s } func getPostByURLTitle(title string) Post { - for _, post := range posts { - if post.URLTitle == title { - return post + for _, year := range years { + for _, post := range year { + if post.URLTitle == title { + return post + } } } + ////for _, post := range posts { + // if post.URLTitle == title { + // return post + // } + //} return Post{} } -func insertPostAccordingToDate(post Post, arr []Post) []Post { - for i, p := range arr { +func insertPostAccordingToDate(post Post, postSlice []Post) []Post { + for i, p := range postSlice { if p.Date.After(post.Date) { - s := make([]Post, len(arr)+1, cap(arr)+1) - copy(s[:], arr[:]) //make a copy of the slice - copy(s[i+1:], arr[i:]) //move the upper part of the slice ahead, creating a hole + s := make([]Post, len(postSlice)+1, cap(postSlice)+1) + copy(s[:], postSlice[:]) //make a copy of the slice + copy(s[i+1:], postSlice[i:]) //move the upper part of the slice ahead, creating a hole s[i] = post //insert new element into hole return s } } - posts = append(posts, post) - return posts + postSlice = append(postSlice, post) + return postSlice } diff --git a/templates/blog.tmpl b/templates/blog.tmpl index d5213b4..46d2f80 100644 --- a/templates/blog.tmpl +++ b/templates/blog.tmpl @@ -7,46 +7,11 @@ -
-
    -
  • -

    {{.Title}}

    -
    -

    play, talk, develop

    -
    -
  • -
  • -
  • -
-
+ {{template "title" .}}
    -
  • - -
  • -
  • -
    - {{if eq .CurrentPage "blog"}} -
    {{template "content" .}}
    - {{else if eq .CurrentPage "about"}} -
    {{template "about" .}}
    - {{else if eq .CurrentPage "past"}} -
    {{template "past" .}}
    - {{else if eq .CurrentPage "keru_shoujo"}} -
    {{template "keru_shoujo" .}}
    - {{else if eq .CurrentPage "contact"}} -
    {{template "contact" .}}
    - {{end}} -
    -
  • + {{template "navbar" .}} + {{template "main" .}}
diff --git a/templates/main.tmpl b/templates/main.tmpl new file mode 100644 index 0000000..52ca0bb --- /dev/null +++ b/templates/main.tmpl @@ -0,0 +1,17 @@ +{{define "main"}} +
  • +
    + {{if eq .CurrentPage "blog"}} +
    {{template "content" .}}
    + {{else if eq .CurrentPage "about"}} +
    {{template "about" .}}
    + {{else if eq .CurrentPage "past"}} +
    {{template "past" .}}
    + {{else if eq .CurrentPage "keru_shoujo"}} +
    {{template "keru_shoujo" .}}
    + {{else if eq .CurrentPage "contact"}} +
    {{template "contact" .}}
    + {{end}} +
    +
  • +{{end}} diff --git a/templates/navbar.tmpl b/templates/navbar.tmpl new file mode 100644 index 0000000..7f45416 --- /dev/null +++ b/templates/navbar.tmpl @@ -0,0 +1,12 @@ +{{define "navbar"}} +
  • + +
  • +{{end}} diff --git a/templates/past.tmpl b/templates/past.tmpl index 14898e1..3ae7800 100644 --- a/templates/past.tmpl +++ b/templates/past.tmpl @@ -1,17 +1,28 @@ {{define "past"}}
    -
      - {{with .Posts}} +
        + {{with .Years}} {{range .}} -
      • -
        -
        +
      • + + + {{(index . 0).Year}} +
      • + {{range .}} +
      • +
        + -
        +
        +
        {{.NormalDate}} -
        -
        {{end}}{{end}} + + +
      • + {{end}} +
      • + {{end}} + {{end}}
    {{end}} diff --git a/templates/title.tmpl b/templates/title.tmpl new file mode 100644 index 0000000..c2cd005 --- /dev/null +++ b/templates/title.tmpl @@ -0,0 +1,14 @@ +{{define "title"}} +
    +
      +
    • +

      {{.Title}}

      +
      +

      play, talk, develop

      +
      +
    • +
    • +
    • +
    +
    +{{end}}