-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
48 lines (42 loc) · 1.97 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{{- $defaultConfigFile := "default.config.yml" -}}
{{- $defaultConfigFileContent := (include $defaultConfigFile | splitFrontMatter) -}}
{{- $config := $defaultConfigFileContent.Meta -}}
{{- $content := false }}
{{- $hostDomains := split "." .Host -}}
{{- $contentDir := printf "subdomains/%s" $hostDomains._0 -}}
{{- $configFilePath := printf "%s/.config.yml" $contentDir -}}
{{- $config = $config | merge (dict "rootdir" $contentDir) -}}
{{- if (fileExists $configFilePath) -}}
{{- $configFileContent := (include $configFilePath | splitFrontMatter) -}}
{{- $config = mergeOverwrite $config $configFileContent.Meta -}}
{{- end -}}
{{- $pathParts := splitList "/" .OriginalReq.URL.Path -}}
{{- $contentFilename := default "index" (slice $pathParts 1 | join "/") -}}
{{- $contentFilePath := printf "%s/%s.md" $contentDir $contentFilename -}}
{{- if (fileExists $contentFilePath) -}}
{{- $contentFileContent := (include $contentFilePath | splitFrontMatter) -}}
{{- $pageConfig := $contentFileContent.Meta -}}
{{- $content := $contentFileContent.Body -}}
{{- $config = mergeOverwrite $config $pageConfig -}}
{{- $_ := set $config "dir" $contentDir -}}
{{- $themePath := printf "themes/%s/" $config.theme -}}
{{- $pageTemplate := printf "%s/%s.html" $themePath $config.template -}}
{{- include $pageTemplate $config $content -}}
{{- else -}}
{{- $pathName := (slice $pathParts 1 | join "/") -}}
{{- $pathPath := printf "%s/%s" $contentDir $pathName -}}
{{- if fileExists $pathPath -}}
{{- $themePath := printf "themes/%s/" $config.theme -}}
{{- $pageTemplate := printf "%s/index.html" $themePath -}}
{{- $_ := set $config "dir" $pathPath -}}
{{- $_ := set $config "urldir" $pathName -}}
{{- include $pageTemplate $config $content -}}
{{- else -}}
{{- httpError 404 -}}
{{- end -}}
{{- end -}}
{{- if $config.debug -}}
<pre><code>config:
{{- toPrettyJson $config -}}
</code></pre>
{{- end -}}