From 8269d33fa2f256b6378bcf3473006fcf9ccf051e Mon Sep 17 00:00:00 2001 From: Hanzei Date: Mon, 25 Jun 2018 15:03:18 +0200 Subject: [PATCH] Cleanup code --- exampleSite/config.toml | 2 - exampleSite/content/blog/_index.md | 6 ++ exampleSite/content/projects/_index.md | 6 ++ layouts/404.html | 39 +++---- layouts/_default/list.html | 39 ++----- layouts/_default/single.html | 34 +----- layouts/_default/taxonomy.html | 36 +------ layouts/_default/terms.html | 74 +++++-------- layouts/blog/list.html | 98 +++++++---------- layouts/blog/single.html | 141 +++++++++++-------------- layouts/index.html | 74 ++++--------- layouts/partials/blogsection.html | 64 +++++------ layouts/partials/footer.html | 28 +++-- layouts/partials/header.html | 2 +- layouts/partials/nav.html | 43 +++++--- layouts/partials/projects.html | 129 +++++++++++----------- layouts/partials/top-icon-with-hr.html | 7 ++ layouts/partials/top-icon.html | 5 + 18 files changed, 357 insertions(+), 470 deletions(-) create mode 100644 exampleSite/content/blog/_index.md create mode 100644 exampleSite/content/projects/_index.md create mode 100644 layouts/partials/top-icon-with-hr.html create mode 100644 layouts/partials/top-icon.html diff --git a/exampleSite/config.toml b/exampleSite/config.toml index aef4ace..9c242cc 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -27,8 +27,6 @@ enforce_ssl = false fadeIn = true # Turn on/off the fade-in effect customCSS = [] # Include custom css files e.g. ["css/foo.css", "css/bar.css"] - showBlog = true # Show Blog section on home page - showProjects = true # Show Projects section on home page projectColumns = "3" # Choose "2" or "3" columns for projects section placeHolderimg = "/img/workday.jpg" # For Projects without image showAllPosts = false # Set 'true' to list all posts on home page, or set 'false' to link to separate blog list page diff --git a/exampleSite/content/blog/_index.md b/exampleSite/content/blog/_index.md new file mode 100644 index 0000000..8703de6 --- /dev/null +++ b/exampleSite/content/blog/_index.md @@ -0,0 +1,6 @@ +--- +title: "Blog" +date: 2017-03-09T13:19:25+08:00 +--- + +Here is some introduction text for my blog diff --git a/exampleSite/content/projects/_index.md b/exampleSite/content/projects/_index.md new file mode 100644 index 0000000..953a147 --- /dev/null +++ b/exampleSite/content/projects/_index.md @@ -0,0 +1,6 @@ +--- +title: "Projects" +date: 2017-03-09T13:19:25+08:00 +--- + +Here is some introduction text for my projects diff --git a/layouts/404.html b/layouts/404.html index ad7b032..d161297 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -1,21 +1,24 @@ {{ partial "header.html" . }} - -
- -
-

404

-
- - -
- {{ partial "nav.html" . }} - -
- Oops! Either you've found a bug (in which case, please tell me) or you're just making things up. This page doesn't exist! + +
+ +
+

404

- - -

-{{ partial "footer.html" . }} -
+ + +
+ {{ partial "nav.html" . }} + +
+ Oops! Either you've found a bug (in which case, please tell me) or you're just making things up. This page doesn't exist! +
+ +
+
+
+
+ {{ partial "footer.html" . }} +
+ diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 19da67a..a9e6acb 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,29 +1,23 @@ {{ partial "header.html" . }} +
- +
-

{{ .Title }}

-
- {{ partial "nav.html" . }} - -
+
{{ .Content }} -
- - +
+
-
- -
-
- - - -
-
- + {{ partial "top-icon-with-hr.html" . }} {{ partial "footer.html" . }}
- - - - diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 984db2e..7c2ab32 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,22 +1,17 @@ {{ partial "header.html" . }} - +
- - +
-

{{ .Title }}

-
- {{ partial "nav.html" . }} - +
- {{ if .Params.image }}
@@ -25,35 +20,14 @@ {{ .Content }}
-
{{ template "_internal/disqus.html" . }}
- -
-
- - - -
-
- + {{ partial "top-icon-with-hr.html" . }} {{ partial "footer.html" . }}
- - - diff --git a/layouts/_default/taxonomy.html b/layouts/_default/taxonomy.html index d0f632d..d269d40 100644 --- a/layouts/_default/taxonomy.html +++ b/layouts/_default/taxonomy.html @@ -1,29 +1,22 @@ {{ partial "header.html" . }} +
- +
-

Tagged "{{ lower .Title }}"

-
- {{ partial "nav.html" . }} -
- {{ .Content }}
- - +
-
- -
-
- - - -
-
- + {{ partial "top-icon-with-hr.html" . }} {{ partial "footer.html" . }}
- - - - diff --git a/layouts/_default/terms.html b/layouts/_default/terms.html index 4cb88a2..a0e7f4a 100644 --- a/layouts/_default/terms.html +++ b/layouts/_default/terms.html @@ -1,57 +1,31 @@ {{ partial "header.html" . }} - + +
+ +
+

{{ .Title }}

+
+ -
- -
- -

{{ .Title }}

-
- - - -
- - {{ partial "nav.html" . }} - -
- - {{ .Content }} -
- - -
-
- {{ range $name, $taxonomy := .Site.Taxonomies.tags }} - {{ lower $name }} ({{ len $taxonomy }}) - {{ end }} -
- -
-
- - - -
-
- - {{ partial "footer.html" . }} + +
+ {{ partial "nav.html" . }} +
+ {{ .Content }} +
+
+
+ {{ range $name, $taxonomy := .Site.Taxonomies.tags }} + {{ lower $name }} ({{ len $taxonomy }}) + {{ end }}
-
- - - - + {{ partial "top-icon-with-hr.html" . }} + {{ partial "footer.html" . }} +
+ +
+ diff --git a/layouts/blog/list.html b/layouts/blog/list.html index a2535ad..63219c2 100644 --- a/layouts/blog/list.html +++ b/layouts/blog/list.html @@ -1,65 +1,49 @@ {{ partial "header.html" . }} - -
- -
-

{{ .Site.Params.blogHead | default "Blog" }}

-
- + +
+ +
+

{{ .Title }}

+
+
- - {{ partial "nav.html" . }} - -
- - {{ if .Site.Params.showLatest }} -

Latest Post

- {{ range first 1 (where .Data.Pages.ByPublishDate.Reverse "Section" "blog") }} -
{{ .Date.Format (.Site.Params.dateForm | default "Jan 02, 2006") }} -

{{ .Title }}

-
- {{ .Summary }} - {{ if .Truncated }} - ...Read More - {{ end }} -
+ {{ partial "nav.html" . }} +
+ + {{ .Content }}
- {{ end }} - {{ end }} - -

All Posts

-
    - {{ range .Data.Pages.ByPublishDate }} - {{ if eq .Section "blog" }} - {{ partial "li.html" . }} + +
    + {{ if .Site.Params.showLatest }} +

    Latest Post

    + {{ range first 1 (where .Data.Pages.ByPublishDate.Reverse "Section" "blog") }} +
    {{ .Date.Format (.Site.Params.dateForm | default "Jan 02, 2006") }} +

    {{ .Title }}

    +
    + {{ .Summary }} + {{ if .Truncated }} + ...Read More + {{ end }} +
    +
    + {{ end }} {{ end }} - {{ end }} -
- -
- -
-
- -
+

All Posts

+
    + {{ range .Data.Pages.ByPublishDate }} + {{ if eq .Section "blog" }} + {{ partial "li.html" . }} + {{ end }} + {{ end }} +
+
+ + {{ partial "top-icon-with-hr.html" . }} + {{ partial "footer.html" . }} +
+
- -{{ partial "footer.html" . }} -
-
- - - - + diff --git a/layouts/blog/single.html b/layouts/blog/single.html index 9a949cc..2e2280e 100644 --- a/layouts/blog/single.html +++ b/layouts/blog/single.html @@ -1,88 +1,69 @@ {{ partial "header.html" . }} - -
- -
-

{{ .Site.Params.blogHead | default "Blog" }}

-
- + +
+ +
+

{{ .Site.Params.blogHead | default "Blog" }}

+
+
- - {{ partial "nav.html" . }} - -
-

{{ .Title }}

-
- {{ .Date.Format (.Site.Params.dateForm | default "Jan 02, 2006") }} | - {{ if eq 1 .ReadingTime }}{{ .ReadingTime }} minute read{{ else }}{{ .ReadingTime }} minutes read{{ end }} -
- - {{ if .Site.Params.shareButtons }} -
- Share this: - {{ if .Site.Params.shareTwitter }} - - {{ end }} - {{ if .Site.Params.shareFacebook }} - - - - - {{ end }} - {{ if .Site.Params.sharePinterest }} - - - - - {{ end }} - {{ if .Site.Params.shareGooglePlus }} - - - - - {{ end }} + {{ partial "nav.html" . }} + +
+

{{ .Title }}

+
+ {{ .Date.Format (.Site.Params.dateForm | default "Jan 02, 2006") }} | + {{ if eq 1 .ReadingTime }}{{ .ReadingTime }} minute read{{ else }}{{ .ReadingTime }} minutes read{{ end }}
- {{ end }} - -
- -
- {{ .Content }} -
- -
- {{ template "_internal/disqus.html" . }} + {{ if .Site.Params.shareButtons }} +
+ Share this: + {{ if .Site.Params.shareTwitter }} + + {{ end }} + {{ if .Site.Params.shareFacebook }} + + + + + {{ end }} + {{ if .Site.Params.sharePinterest }} + + + + + {{ end }} + {{ if .Site.Params.shareGooglePlus }} + + + + + {{ end }} +
+ {{ end }} +
+ + +
+ {{ .Content }} +
+ +
+ {{ template "_internal/disqus.html" . }} +
+ {{ partial "top-icon-with-hr.html" . }} + {{ partial "footer.html" . }}
- -
-
- -
+
- -{{ partial "footer.html" . }} -
-
- - - - + diff --git a/layouts/index.html b/layouts/index.html index dafb04c..7de1371 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -35,61 +35,43 @@
+{{ with .Site.GetPage "page" "about" }}
-

About

- +

{{ .Title }}

{{ if .Site.Params.avatar }}
- My profile picture. + My profile picture
{{ end }}
- {{ range .Data.Pages }} - {{if eq .Title "About" }} - {{.Content}} - {{end}} - {{ end }} + {{.Content}}
-
- -
-
+
+ + {{ partial "top-icon.html" . }} +
+

+{{ end }} - {{ if .Site.Params.showProjects }} -
- {{ partial "projects.html" . }} -
- -

- {{ end }} - +{{ partial "projects.html" . }} - {{ if .Site.Params.showBlog }} -
- {{ partial "blogsection.html" . }} -
- -

- {{ end }} +{{ partial "blogsection.html" . }} +{{ with .Site.GetPage "page" "contact" }}
-

Contact

+

{{ .Title }}

- {{ range .Data.Pages }} - {{if eq .Title "Contact" }} - {{.Content}} - {{end}} - {{ end }} + {{.Content}}
{{ if .Site.Params.localTime }} @@ -111,30 +93,20 @@ {{ end }} {{ partial "social.html" . }} -
- -
-
+
+ + {{ partial "top-icon.html" . }} +
+

+{{ end }} {{ partial "footer.html" . }} -
+
+ - - - - diff --git a/layouts/partials/blogsection.html b/layouts/partials/blogsection.html index 62796a6..a2ffea1 100644 --- a/layouts/partials/blogsection.html +++ b/layouts/partials/blogsection.html @@ -1,33 +1,37 @@ -
- -{{ if .Site.Params.showLatest }} -

Latest Post

- {{ range first 1 (where .Data.Pages.ByPublishDate.Reverse "Section" "blog") }} -
{{ .Date.Format (.Site.Params.dateForm | default "Jan 02, 2006") }} -

{{ .Title }}

-
- {{ .Summary }} - {{ if .Truncated }} - ...Read More - {{ end }} +{{ with .Site.GetPage "section" "blog" }} +
+ +
+ {{ if .Site.Params.showLatest }} +

Latest Post

+ {{ range first 1 (where .Data.Pages.ByPublishDate.Reverse "Section" "blog") }} +
{{ .Date.Format (.Site.Params.dateForm | default "Jan 02, 2006") }} +

{{ .Title }}

+
+ {{ .Summary }} + {{ if .Truncated }} + ...Read More + {{ end }} +
-
- {{ end }} -{{ end }} - -{{ if .Site.Params.showAllPosts }} -

All Posts

-
    - {{ range .Data.Pages.ByPublishDate }} - {{ if eq .Section "blog" }} - {{ partial "li.html" . }} + {{ end }} {{ end }} - {{ end }} -
-{{ else }} - + + {{ if .Site.Params.showAllPosts }} +

All Posts

+
    + {{ range .Pages }} + {{ partial "li.html" . }} + {{ end }} +
+ {{ else }} + + {{ end }} +
+ + {{ partial "top-icon.html" . }} +
+ + +

{{ end }} - -
- -
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 78dc47c..bdfbca4 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,9 +1,25 @@ - + + + + diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 95aeddd..e14eccc 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -10,7 +10,7 @@ {{ if .Site.Params.description }}{{ end }} - + {{ $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" }} {{ if eq $url "/" }} diff --git a/layouts/partials/nav.html b/layouts/partials/nav.html index 5fdd97c..513f5f6 100644 --- a/layouts/partials/nav.html +++ b/layouts/partials/nav.html @@ -2,7 +2,8 @@ <div class="container"> <hr> <nav class="nav nav-center"> - {{ if not .Page.IsHome }} + {{ $isHome := .Page.IsHome }} + {{ if not $isHome }} <span id="nav-toggle" class="nav-toggle" onclick="document.getElementById('nav-menu').classList.toggle('is-active');"> <span></span> <span></span> @@ -10,41 +11,51 @@ </span> <div id="nav-menu" class="nav-left nav-menu"> {{ end }} - {{ if not .Page.IsHome }} + {{ if not $isHome }} <a class="nav-item" href="{{ "/" | relURL }}">Main</a> {{ end }} - <a class="nav-item" href="#about">About</a> + {{ with .Site.GetPage "page" "about" }} + <a class="nav-item" href="{{ if $isHome }}#about{{ else }}{{ "/#about" | relURL }}{{ end }}">{{ .Title }}</a> + {{ end }} - {{ if and (.Site.Params.showProjects) (not (and (eq .Page.Section "projects") (eq .Page.Kind "section") )) }} - {{ if .IsHome }} - <a class="nav-item" href="#projects">Projects</a> + {{ $pageIsInProjects := eq .Page.Section "projects"}} + {{ if not (and $pageIsInProjects (eq .Page.Kind "section")) }} + {{ with .Site.GetPage "section" "projects" }} + {{ if $isHome }} + <a class="nav-item" href="#projects">{{ .Title }}</a> {{ else }} <a class="nav-item" href="{{ "/projects" | relURL }}"> - {{ if eq .Section "projects" }} - Back to Projects + {{ if $pageIsInProjects }} + Back to {{ .Title }} {{ else }} - Projects + {{ .Title }} {{ end }} </a> {{ end }} {{ end }} + {{ end }} - {{ if and (.Site.Params.showBlog) (not (and (eq .Page.Section "blog") (eq .Page.Kind "section") )) }} - {{ if .IsHome }} - <a class="nav-item" href="#blog">Blog</a> + {{ $pageIsInBlog := eq .Page.Section "blog"}} + {{ if not (and $pageIsInBlog (eq .Page.Kind "section")) }} + {{ with .Site.GetPage "section" "blog" }} + {{ if $isHome }} + <a class="nav-item" href="#blog">{{ .Title }}</a> {{ else }} <a class="nav-item" href="{{ "/blog" | relURL }}"> - {{ if eq .Section "blog" }} - Back to Blog + {{ if $pageIsInBlog }} + Back to {{ .Title | singularize}} {{ else }} - Blog + {{ .Title | singularize}} {{ end }} </a> {{ end }} {{ end }} + {{ end }} - <a class="nav-item" href="#contact">Contact</a> + {{ with .Site.GetPage "page" "contact" }} + <a class="nav-item" href="{{ if $isHome }}#contact{{ else }}{{ "/#contact" | relURL }}{{ end }}">{{ .Title }}</a> + {{ end }} {{ if and .Site.Params.showRSSButton .Site.RSSLink }} <a class="nav-item" href="{{ .Site.RSSLink }}"><i class="fa fa-rss"></i></a> diff --git a/layouts/partials/projects.html b/layouts/partials/projects.html index 1adef84..488c2cb 100644 --- a/layouts/partials/projects.html +++ b/layouts/partials/projects.html @@ -1,70 +1,71 @@ -<div class="container"> +{{ with .Site.GetPage "section" "projects" }} +<div class="section" id="projects"> <!-- Begin Projects container --> - <h2 class="title is-2 has-text-centered">Projects</h2> - - <div class="section is-small"> - <div class="columns is-multiline"> - {{ range sort .Pages }} {{ if eq .Section "projects" }} - {{ if eq .Site.Params.projectColumns "2" }} - <div class="column is-half"> {{ else if eq .Site.Params.projectColumns "3" }} - <div class="column is-one-third"> {{ else }} - <div class="column is-one-third"> {{ end }} - <!-- Hey Vicky, show half column if number is even. --> - <div {{ if not .Params.external_link }} id="project{{ $card := .Title | urlize }}{{ replace $card "%" ""}}" {{ end }} class="card"> - <div class="card-image"> - <figure class="image is-3by2"> - <a {{ if .Params.external_link }} href="{{ .Params.external_link }}" {{ end }}> - <img src="{{ if .Params.image }}{{ .Params.image | relURL }}{{ else }}{{ (.Site.Params.placeHolderimg | default "/img/workday.jpg") | relURL }}{{ end }}"> - </a> - </figure> - </div> - <div class="card-content has-text-centered top-pad"> - <a {{ if .Params.external_link }} href="{{ .Params.external_link }}" {{ end }}> - {{ .Title }} - </a> - </div> + <div class="container"> + <h2 class="title is-2 has-text-centered">{{ .Title }}</h2> + <div class="section is-small"> + <div class="columns is-multiline"> + {{ range sort .Pages }} + {{ if eq .Site.Params.projectColumns "2" }} + <div class="column is-half"> {{ else if eq .Site.Params.projectColumns "3" }} + <div class="column is-one-third"> {{ else }} + <div class="column is-one-third"> {{ end }} + <!-- Hey Vicky, show half column if number is even. --> + <div {{ if not .Params.external_link }} id="project{{ $card := .Title | urlize }}{{ replace $card "%" ""}}" {{ end }} class="card"> + <div class="card-image"> + <figure class="image is-3by2"> + <a {{ if .Params.external_link }} href="{{ .Params.external_link }}" {{ end }}> + <img src="{{ if .Params.image }}{{ .Params.image | relURL }}{{ else }}{{ (.Site.Params.placeHolderimg | default "/img/workday.jpg") | relURL }}{{ end }}"> + </a> + </figure> + </div> + <div class="card-content has-text-centered top-pad"> + <a {{ if .Params.external_link }} href="{{ .Params.external_link }}" {{ end }}> + {{ .Title }} + </a> + </div> + </div> </div> - </div> - {{ end }} {{ end }} + {{ end }} + </div> </div> -</div> -</div> -<!-- End Projects container --> - -<!-- Projects modals --> -{{ range sort .Pages }} {{ if eq .Section "projects" }} {{ if not .Params.external_link }} -<div class="modal" id="modal{{ $card := .Title | urlize }}{{ replace $card "%" ""}}"> - <div class="modal-background"></div> - <div class="modal-card"> - {{ with .Title }} - <header class="modal-card-header bottom-pad"> - <p class="modal-card-title has-text-centered">{{ . }}</p> - </header> - {{ end }} - {{ if .Params.image }} - <img src="{{ .Params.image | relURL }}" class="img-responsive img-centered"> - {{ end }} - {{ if .Content }} - <section class="modal-card-body markdown"> - {{ .Content }} - </section> - {{ end }} </div> - <button class="modal-close is-large" aria-label="close" id="close{{ $card := .Title | urlize }}{{ replace $card "%" ""}}"></button> -</div> -<script> - $('#project{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').click(function() { - $('#modal{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').addClass('is-active'); - }); - $('#close{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').click(function() { - $('#modal{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').removeClass('is-active'); - }); -</script> -{{ end }} {{ end }} {{ end }} + <!-- End Projects container --> - -<div class="container has-text-centered top-pad"> - <a href="#top"> - <i class="fa fa-arrow-up"></i> - </a> + <!-- Projects modals --> + {{ range sort .Pages }} + {{ if not .Params.external_link }} + <div class="modal" id="modal{{ $card := .Title | urlize }}{{ replace $card "%" ""}}"> + <div class="modal-background"></div> + <div class="modal-card"> + {{ with .Title }} + <header class="modal-card-header bottom-pad"> + <p class="modal-card-title has-text-centered">{{ . }}</p> + </header> + {{ end }} + {{ if .Params.image }} + <img src="{{ .Params.image | relURL }}" class="img-responsive img-centered"> + {{ end }} + {{ if .Content }} + <section class="modal-card-body markdown"> + {{ .Content }} + </section> + {{ end }} + </div> + <button class="modal-close is-large" aria-label="close" id="close{{ $card := .Title | urlize }}{{ replace $card "%" ""}}"></button> + </div> + <script> + $('#project{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').click(function() { + $('#modal{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').addClass('is-active'); + }); + $('#close{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').click(function() { + $('#modal{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').removeClass('is-active'); + }); + </script> + {{ end }} {{ end }} + {{ partial "top-icon.html" . }} </div> +<!-- End Projects section --> + +<div class="container"><hr></div> +{{ end }} diff --git a/layouts/partials/top-icon-with-hr.html b/layouts/partials/top-icon-with-hr.html new file mode 100644 index 0000000..a077275 --- /dev/null +++ b/layouts/partials/top-icon-with-hr.html @@ -0,0 +1,7 @@ +<div class="container top-pad"> + <hr> +</div> +{{ partial "top-icon.html" . }} +<div class="container top-pad"> + <hr> +</div> diff --git a/layouts/partials/top-icon.html b/layouts/partials/top-icon.html new file mode 100644 index 0000000..015516f --- /dev/null +++ b/layouts/partials/top-icon.html @@ -0,0 +1,5 @@ +<div class="container has-text-centered top-pad"> + <a href="#top"> + <i class="fa fa-arrow-up"></i> + </a> +</div>