Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor layouts rework #170

Merged
merged 5 commits into from
Mar 24, 2020
Merged

Minor layouts rework #170

merged 5 commits into from
Mar 24, 2020

Conversation

inwardmovement
Copy link
Contributor

@inwardmovement inwardmovement commented Mar 22, 2020

Fixes #162

  • We can remove layout declaration from content files (including content/_index.md) as Hugo's template lookup order make them use layouts/icons/single.html (for icons pages) and layouts/home.html (for home page) automatically.
  • Reworked 404 to benefit from template lookup order too.
  • Created single.html and list.html layouts to get rid of the warning, but I suggest we use a baseof.html default template that would fetch a main block from other templates and include the scripts partial (which would fetch JQuery, Popper, Bootstrap...)

Suggested layouts organization (I could take care of this):
baseof.html

<!doctype html>
<html lang="en">
  <head>
    {{ partial "header" . }}
  </head>
  <body id="icons-body">
    {{ partial "skippy" . }}
    {{ partial "navbar" . }}
    {{ block "main" . }}{{ end }}
    {{- partial "footer" . }}
    {{- partial "scripts" . }}
  </body>
</html>

single.html

{{ define "main" }}
  {{ partial "hero" . }}

  <main class="container" id="content" role="main">
    {{ .Content }}
  </main>
{{ end }}

list.html

{{ define "main" }}
  {{ partial "hero" . }}

  <main class="container" id="content" role="main">
    <ul>
      {{ range .Pages }}
        <li>
          <a href="{{ .Permalink }}">{{.Title}}</a>
        </li>
      {{ end }}
      </ul>
  </main>
{{ end }}

home.html

{{ define "main" }}
  {{ partial "hero" . }}
  
  <main class="container" id="content" role="main">
    {{ partial "icons" . }}
    {{ .Content }}
  </main>
{{ end }}

icons/single.html

{{ define "main" }}
  <main class="container" id="content" role="main">
    <nav>
      <ul class="breadcrumb my-4 text-muted bg-transparent p-0">
        <li class="breadcrumb-item"><a href="/">Icons</a></li>
        <li class="breadcrumb-item">{{ .Title }}</li>
      </ul>
    </nav>

    <div class="row align-items-md-center">
      <div class="col-md-8">
        <h1>{{ .Title }}</h1>
        <p class="mb-3 mb-md-0">Tags: {{ with .Params.tags }}{{ delimit . ", " }}{{ end }}</p>
      </div>
      <div class="col-md-4">
        <script async src="https://cdn.carbonads.com/carbon.js?serve=CE7D4277&placement=iconsgetbootstrapcom" id="_carbonads_js"></script>
      </div>
    </div>

    <hr class="my-4">

    {{- $filenameWithExt := split .Name "." -}}
    {{- $filename := index $filenameWithExt 0 -}}
    {{- $name := humanize $filename -}}

    <div class="row mb-4">
      <div class="col-md-6">
        <div class="d-flex align-items-center justify-content-center p-3 py-5 mb-2 bg-light rounded" style="font-size: 20em;">
          {{ readFile (printf "/%s/%s.svg" "icons" .File.TranslationBaseName) | chomp | safeHTML }}
        </div>
      </div>
      <div class="col-md-3">
        <div class="d-flex align-items-center justify-content-center p-3 py-5 mb-2 bg-light rounded" style="font-size: 10em">
          {{ readFile (printf "/%s/%s.svg" "icons" .File.TranslationBaseName) | chomp | safeHTML }}
        </div>
      </div>
      <div class="col-md-2">
        <div class="d-flex align-items-center justify-content-center p-3 py-5 mb-2 bg-light rounded" style="font-size: 2em">
          {{ readFile (printf "/%s/%s.svg" "icons" .File.TranslationBaseName) | chomp | safeHTML }}
        </div>
      </div>
      <div class="col-md-1">
        <div class="d-flex align-items-center justify-content-center p-3 py-4 mb-2 bg-light rounded" style="font-size: 1em">
          {{ readFile (printf "/%s/%s.svg" "icons" .File.TranslationBaseName) | chomp | safeHTML }}
        </div>
      </div>
    </div>

    <h2 class="h4 mb-3">Copy SVG code</h2>
    <div class="alert alert-info">Copy to clipboard button hopefully coming in next release, sorry!</div>

    {{- $source := readFile (printf "/%s/%s.svg" "icons" .File.TranslationBaseName) }}
    {{ highlight $source "html" "" }}
  </main>
{{ end }}

@mdo mdo requested a review from XhmikosR March 23, 2020 19:58
@mdo
Copy link
Member

mdo commented Mar 23, 2020

This sounds great to me, in particular the suggestions you're making about how to build on the changes here as I love the idea of nesting the layouts like this. I'm still very new to Hugo, so PRs like this are perfect for me to better understand things.

Let's get @XhmikosR to weigh in before we figure out an approach.

@XhmikosR
Copy link
Member

XhmikosR commented Mar 23, 2020

I'll have a close look tomorrow, thanks for the PR! And I definitely agree we should use a baseof.html, which is something we need to do in Bootstrap's docs too and leverage Hugo's template lookup hierarchy (I really need to find some time and get some help there 🙂)

BTW, I just noticed the homepage links to each icon page are missing the trailing slash. I'll try to fix it tomorrow unless someone beats me to it. EDIT: this was simpler than I thought, #172

@XhmikosR XhmikosR added the docs Improvements or additions to documentation label Mar 23, 2020
@XhmikosR
Copy link
Member

Let's land this and you can make the other layout changes to another PR, @inwardmovement. Thanks!

@XhmikosR XhmikosR merged commit 8b20847 into twbs:master Mar 24, 2020
@inwardmovement inwardmovement deleted the minor-layouts-rework branch March 24, 2020 19:38
begrafx pushed a commit to begrafx/icons that referenced this pull request Apr 6, 2020
* remove layout from icons content files

* remove unnecessary layout in home content file

* remove layout in 404 content file and move 404.html

* create default single and list layouts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Hugo warning/leverage Hugo layout hierarchy order
3 participants