Skip to content

Commit

Permalink
Merge pull request #43 from mansoorbarri/refactor
Browse files Browse the repository at this point in the history
modularise head.html
  • Loading branch information
mansoorbarri authored Jan 9, 2025
2 parents 9b44d5f + 615981b commit c115923
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 45 deletions.
46 changes: 1 addition & 45 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,51 +1,7 @@
<!DOCTYPE html>
<html class="no-js" lang="{{ .Site.Language.Lang }}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ block "title" . }}{{ if not .IsHome }}{{ .Title }} - {{ end }}{{ .Site.Title }}{{ end }}</title>
<script>(function(d,e){d[e]=d[e].replace("no-js","js");})(document.documentElement,"className");</script>
<meta name="description" content="{{ if .IsHome }}{{ .Site.Params.description }}{{ else }}{{ .Params.Description }}{{ end }}">
{{- if .Site.Params.opengraph }}
{{ template "_internal/opengraph.html" . }}
{{- end }}
{{- if .Site.Params.schema }}
{{ template "_internal/schema.html" . }}
{{- end }}
{{- if .Site.Params.twitter_cards }}
{{ template "_internal/twitter_cards.html" . }}
{{- end }}

{{- $googleFontsLink := .Site.Params.googleFontsLink | default "https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700" }}
{{- if hasPrefix $googleFontsLink "https://fonts.googleapis.com/" }}
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="dns-prefetch" href="//fonts.googleapis.com">
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link rel="stylesheet" {{ printf `href="%s"` $googleFontsLink | safeHTMLAttr }}>
{{- end }}

{{ $style := resources.Get "css/style.css" | resources.ExecuteAsTemplate "css/style.css" . -}}
<link rel="stylesheet" href="{{ $style.RelPermalink }}">
{{ $v2Styles := resources.Get "css/v2-styles.css" | resources.ExecuteAsTemplate "css/v2-styles.css" . -}}
<link rel="stylesheet" href="{{ $v2Styles.RelPermalink }}">
{{ range .Site.Params.customCSS -}}
<link rel="stylesheet" href="{{ . | relURL }}">
{{- end }}

{{- with .OutputFormats.Get "rss" }}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s">` .Rel .MediaType.Type .RelPermalink $.Site.Title | safeHTML }}
{{- end }}

<link rel="shortcut icon" href="{{ "favicon.ico" | relURL }}">
{{- $server := "" }}
{{- if gt (int (index (split hugo.Version ".") 1)) "120" }}
{{ $server = hugo.IsServer }}
{{- else }}
{{ $server = .Site.IsServer }}
{{- end -}}
{{- if not $server }}
{{ template "_internal/google_analytics.html" . }}
{{- end }}
{{- partial "head.html" . -}}
</head>
<body class="body">
<div class="container container--outer">
Expand Down
20 changes: 20 additions & 0 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ block "title" . }}{{ if not .IsHome }}{{ .Title }} - {{ end }}{{ .Site.Title }}{{ end }}</title>
<script>(function(d,e){d[e]=d[e].replace("no-js","js");})(document.documentElement,"className");</script>

{{- partial "head/seo.html" . -}}

{{- partial "head/gfonts.html" . -}}

{{- partial "head/stylesheet.html" . -}}

{{- $server := "" }}
{{- if gt (int (index (split hugo.Version ".") 1)) "120" }}
{{ $server = hugo.IsServer }}
{{- else }}
{{ $server = .Site.IsServer }}
{{- end -}}
{{- if not $server }}
{{ template "_internal/google_analytics.html" . }}
{{- end }}
7 changes: 7 additions & 0 deletions layouts/partials/head/gfonts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- $googleFontsLink := .Site.Params.googleFontsLink | default "https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700" }}
{{- if hasPrefix $googleFontsLink "https://fonts.googleapis.com/" }}
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="dns-prefetch" href="//fonts.googleapis.com">
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link rel="stylesheet" {{ printf `href="%s"` $googleFontsLink | safeHTMLAttr }}>
{{- end }}
17 changes: 17 additions & 0 deletions layouts/partials/head/seo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<meta name="description" content="{{ if .IsHome }}{{ .Site.Params.description }}{{ else }}{{ .Params.Description }}{{ end }}">

{{- if .Site.Params.opengraph }}
{{ template "_internal/opengraph.html" . }}
{{- end }}
{{- if .Site.Params.schema }}
{{ template "_internal/schema.html" . }}
{{- end }}
{{- if .Site.Params.twitter_cards }}
{{ template "_internal/twitter_cards.html" . }}
{{- end }}

{{- with .OutputFormats.Get "rss" }}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s">` .Rel .MediaType.Type .RelPermalink $.Site.Title | safeHTML }}
{{- end }}

<link rel="shortcut icon" href="{{ "favicon.ico" | relURL }}">
7 changes: 7 additions & 0 deletions layouts/partials/head/stylesheet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ $style := resources.Get "css/style.css" | resources.ExecuteAsTemplate "css/style.css" . -}}
<link rel="stylesheet" href="{{ $style.RelPermalink }}">
{{ $v2Styles := resources.Get "css/v2-styles.css" | resources.ExecuteAsTemplate "css/v2-styles.css" . -}}
<link rel="stylesheet" href="{{ $v2Styles.RelPermalink }}">
{{ range .Site.Params.customCSS -}}
<link rel="stylesheet" href="{{ . | relURL }}">
{{- end }}

0 comments on commit c115923

Please sign in to comment.