Skip to content

Commit

Permalink
Wrap .File.Dir in conditionals to prevent warning
Browse files Browse the repository at this point in the history
Fixes: #728
  • Loading branch information
stp-ip committed Apr 23, 2020
1 parent 8b10f68 commit 3722c7d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
3 changes: 3 additions & 0 deletions exampleSite/config-dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ enableGitInfo = true
version = "0.16.2"
disableKinds = ["RSS", "taxonomy", "taxonomyTerm"]

RelativeURLs = true
CanonifyURLs = true

# Google Analytics tracking
googleAnalytics = ""

Expand Down
4 changes: 2 additions & 2 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- define "main" -}}
{{/* In some edge cases, .CurrentSection is not available. If it's not
available the build would break since we need .CurrentSection.File.Dir later on. */}}
{{- /* In some edge cases, .CurrentSection is not available. If it's not
available the build would break since we need .CurrentSection.File.Dir later on. */ -}}
{{- if .CurrentSection -}}
{{- $list_page := .Site.GetPage "page" (printf "%s%s" .CurrentSection.File.Dir "_index") -}}
{{/* real_page is the _index.md file which indicates the page that is
Expand Down
16 changes: 9 additions & 7 deletions layouts/partials/fragments/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
{{- partial "helpers/container.html" (dict "start" true "in_slot" .in_slot "bg" $bg "Name" .Name "Params" .Params) -}}
<div data-portal></div>
{{- partial "helpers/container.html" (dict "end" true "in_slot" .in_slot) -}}
<script>
(window.editors || (window.editors = [])).push({
ui: JSON.parse({{ readFile (printf "%s%s/ui.json" .page.File.Dir .Name) | safeHTML }}),
schema: JSON.parse({{ readFile (printf "%s%s/schema.json" .page.File.Dir .Name) | safeHTML }}),
container: {{ printf "#%s [data-portal]" .Name }}
});
</script>
{{- if .page.File.Dir -}}
<script>
(window.editors || (window.editors = [])).push({
ui: JSON.parse({{ readFile (printf "%s%s/ui.json" .page.File.Dir .Name) | safeHTML }}),
schema: JSON.parse({{ readFile (printf "%s%s/schema.json" .page.File.Dir .Name) | safeHTML }}),
container: {{ printf "#%s [data-portal]" .Name }}
});
</script>
{{- end -}}
16 changes: 9 additions & 7 deletions layouts/partials/fragments/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
<canvas id="{{ printf "chart-%s" .Name }}" width="400" height="400"></canvas>
</div>
{{- partial "helpers/container.html" (dict "end" true "in_slot" .in_slot) -}}
<script>
var fragmentName = "{{ .Name }}";
window.syna.api.register('graph', 'graph-' + fragmentName, {
selector: "{{ printf "#chart-%s" .Name }}",
config: JSON.parse({{ readFile (printf "%s%s/config.json" .page.File.Dir .Name) | safeHTML }}),
});
</script>
{{- if .page.File.Dir -}}
<script>
var fragmentName = "{{ .Name }}";
window.syna.api.register('graph', 'graph-' + fragmentName, {
selector: "{{ printf "#chart-%s" .Name }}",
config: JSON.parse({{ readFile (printf "%s%s/config.json" .page.File.Dir .Name) | safeHTML }}),
});
</script>
{{- end -}}
20 changes: 11 additions & 9 deletions layouts/partials/fragments/hero.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@
</div>
</header>
{{- if .Params.particles }}
<script>
var fragmentName = "{{ .Name }}";
{{- $file_path := printf "%s%s/config.json" .page.File.Dir .Name -}}
window.syna.api.register("hero", "hero-" + fragmentName, {
selector: "{{ printf "%s-particles-js" .Name }}",
config: {{ if fileExists $file_path -}} JSON.parse({{ readFile $file_path | safeHTML }}) {{- else -}} null {{- end -}},
});
</script>
{{ end -}}
{{- if .page.File.Dir -}}
<script>
var fragmentName = "{{ .Name }}";
{{- $file_path := printf "%s%s/config.json" .page.File.Dir .Name -}}
window.syna.api.register("hero", "hero-" + fragmentName, {
selector: "{{ printf "%s-particles-js" .Name }}",
config: {{ if fileExists $file_path -}} JSON.parse({{ readFile $file_path | safeHTML }}) {{- else -}} null {{- end -}},
});
</script>
{{ end -}}
{{ end -}}

0 comments on commit 3722c7d

Please sign in to comment.