Skip to content

Commit 3ff759a

Browse files
committed
shortcodes/static-path.html: Call the partial with same name instead
With a new partial that contains code achieving the same functionality, this is an obviously reasonable change to eliminate duplicate code.
1 parent 3bee325 commit 3ff759a

1 file changed

Lines changed: 12 additions & 68 deletions

File tree

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,8 @@
11
{{/*
22
Based on this site's convention for organizing static files, returns the full
3-
relative path of a static file to the site base URL. The returned path's value
4-
depends on the current page's permalink, section, kind, and draft status.
5-
6-
This site's static files are organized in the following convention:
7-
- The files are organized by their types under different directories in the
8-
union of all static directories, like 'static/img/' for images, and
9-
'static/res/' for miscellaneous resources.
10-
- Under each type's directory are static files of that type for the section of
11-
this site whose name is the same as the directory, such as
12-
'static/img/collections/' for all images used in the 'collections' section,
13-
and 'static/res/posts/' for all resources used in the 'posts' section.
14-
15-
With respect to the basic conventions above, the exact path relative to a
16-
section's directory is determined as follows:
17-
- For each post that is not a draft: The post's date in 'YYYY-MM-DD' format,
18-
followed by a hyphen, and the last element of the post's permalink with any
19-
extension stripped. e.g. '2006/01/02/lorem-ipsum.html' ->
20-
'static/img/posts/2006-01-02-lorem-ipsum/'
21-
- For each draft post: The string 'drafts/', followed by the last element of
22-
the post's permalink with any extension stripped. e.g.
23-
'2006/01/02/lorem-ipsum.html' -> 'static/img/posts/drafts/lorem-ipsum/'
24-
- For each page in other sections: The page's permalink relative to the root of
25-
the section it is in, with any extension stripped. e.g.
26-
- 'collections/hugo/shortcode.html' ->
27-
'static/img/collections/hugo/shortcode/'
28-
- 'collections/hugo.html' -> 'static/img/collections/hugo/'
29-
30-
Finally, under every path derived from the above rules, a directory whose name
31-
is the same as a locale's language code (i.e. what '.Language.Lang' returns)
32-
can be optionally created to store localized static files for the locale. Any
33-
static files not in such a directory are unlocalized files that may be shared
34-
across all multilingual variants of the site. For example:
35-
- 'static/img/posts/2006-01-02-lorem-ipsum/en/' contains the post's images
36-
that are localized for English
37-
- 'static/img/posts/2006-01-02-lorem-ipsum/' is for images that can be shared
38-
among all locales
3+
relative path of a static file to the site base URL. The convention is
4+
documented in the top comment of this site's partial template
5+
'static-path.html'.
396

407
Named Parameters:
418
- type: The static file's type, such as 'img' and 'res'
@@ -70,7 +37,7 @@
7037
{{- end }}
7138

7239
{{- with .Get "file" }}
73-
{{- $file = printf "/%s" . }}
40+
{{- $file = . }}
7441
{{- end }}
7542

7643
{{- $l10n = gt (.Get "l10n" | len) 0 }}
@@ -83,7 +50,7 @@
8350
{{- end }}
8451

8552
{{- with .Get 1 }}
86-
{{- $file = printf "/%s" . }}
53+
{{- $file = . }}
8754
{{- end }}
8855

8956
{{- range after 2 .Params }}
@@ -95,33 +62,10 @@
9562
{{- end }}
9663
{{- end }}
9764

98-
{{- $l10nDir := cond $l10n (printf "/%s" .Page.Language.Lang) "" }}
99-
100-
{{- with .Page }}
101-
{{- $path := "" }}
102-
{{- $pageBaseName := path.BaseName .RelPermalink }}
103-
{{- if eq .Section "posts" }}
104-
{{- $path = printf "%s/posts/%s%s%s%s"
105-
$type
106-
(cond .Draft "drafts/" (.Date.Format "2006-01-02-"))
107-
$pageBaseName
108-
$l10nDir
109-
$file
110-
}}
111-
{{- else }}
112-
{{- /* Hugo starts .Page.RelPermalink with .Site.LanguagePrefix
113-
and may end it with '/', which can be removed by path.Clean */}}
114-
{{- $pageURLParent := replace (path.Clean .RelPermalink | path.Dir)
115-
.Site.LanguagePrefix ""
116-
1
117-
}}
118-
{{- $path = printf "%s%s/%s%s%s"
119-
$type
120-
$pageURLParent
121-
$pageBaseName
122-
$l10nDir
123-
$file
124-
}}
125-
{{- end }}
126-
{{- cond $abs (absURL $path) (relURL $path) }}
127-
{{- end -}}
65+
{{- partial "static-path.html" (dict
66+
"page" .Page
67+
"type" $type
68+
"file" $file
69+
"l10n" $l10n
70+
"abs" $abs
71+
) -}}

0 commit comments

Comments
 (0)