Skip to content

Commit

Permalink
Make contact page config more robust
Browse files Browse the repository at this point in the history
Ensures the contact page is properly rendered when some contact details 
are missing from config or invalid.

Fixes #197
  • Loading branch information
salim-b committed Sep 12, 2021
1 parent 4932bd3 commit ec7c4b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
27 changes: 14 additions & 13 deletions layouts/_default/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<section class="contact-form">
<div class="container">
{{ with site.Params.contact.form }}{{ if .enable }}
{{ with site.Params.contact.form }}{{ if .enable -}}
<div class="row">
<form method="POST" {{ if .use_netlify }}name="{{ printf "contact_%s" $.Language.Lang }}" action="{{ "/message_sent" | relLangURL }}" netlify netlify-honeypot="nhp"{{ else }}name="contact" action="{{ .action | safeURL }}"{{ end }}>
<div class="col-md-6 col-sm-12">
Expand All @@ -21,11 +21,11 @@
<label for="subject" hidden>{{ i18n "contact_form_subject" }}</label>
<input id="subject" name="subject" type="text" class="form-control" placeholder="{{ i18n "contact_form_subject" }}" required>
</div>
{{ if .use_netlify }}
{{ if .use_netlify -}}
<div class="form-group-h">
<input name="nhp" type="text" class="form-control" placeholder="Are you made of flesh and bone?">
</div>
{{ end -}}
{{- end }}
</div>
</div>
<div class="col-md-6 col-sm-12">
Expand All @@ -39,34 +39,35 @@
</div>
</form>
</div>
{{ end }}{{ end }}
{{- end }}{{ end }}
<div class="contact-box row">
{{ with site.Params.contact }}
{{ with site.Params.contact -}}
<div class="col-md-6 col-sm-12">
<div class="block">
<h2>{{ i18n "address_title" }}</h2>
<ul class="address-block">
{{ if isset . "location" }}<li><i class="ion-ios-location-outline"></i>{{ if .address_descriptors }}{{ i18n "location" | printf "%s: " }}{{ end }}<div>{{ .location | markdownify }}</div></li>{{ end }}
{{ if isset . "email" }}<li><i class="ion-ios-email-outline"></i>{{ if .address_descriptors }}{{ i18n "email" | printf "%s: " }}{{ end }}{{ partial "cloak_email" .email }}</li>{{ end }}
{{ if isset . "phone" }}<li><i class="ion-ios-telephone-outline"></i>{{ if .address_descriptors }}{{ i18n "phone" | printf "%s: " }}{{ end }}{{ .phone }}</li>{{ end }}
{{ $add_address_descriptors := .address_descriptors }}
{{ with .location }}<li><i class="ion-ios-location-outline"></i>{{ if $add_address_descriptors }}{{ i18n "location" | printf "%s: " }}{{ end }}<div>{{ . | markdownify }}</div></li>{{ end }}
{{ with .email }}<li><i class="ion-ios-email-outline"></i>{{ if $add_address_descriptors }}{{ i18n "email" | printf "%s: " }}{{ end }}{{ partial "cloak_email" . }}</li>{{ end }}
{{ with .phone }}<li><i class="ion-ios-telephone-outline"></i>{{ if $add_address_descriptors }}{{ i18n "phone" | printf "%s: " }}{{ end }}{{ . }}</li>{{ end }}
</ul>
<ul class="social-icons">
{{ range site.Params.social }}
{{ range site.Params.social -}}
<li><a href="{{ .link | safeURL }}"><i class="{{ .icon }}"></i></a></li>
{{ end }}
{{- end }}
</ul>
</div>
</div>
{{ end }}
{{ if site.Params.gmap.enable }}
{{- end }}
{{ if site.Params.gmap.enable -}}
<div class="col-md-6 col-sm-12">
<div class="block">
<div class="google-map">
<div class="map" id="map" data-latitude="{{ site.Params.gmap.map_latitude }}" data-longitude="{{ site.Params.gmap.map_longitude }}" data-marker="{{ site.Params.gmap.map_marker | relURL }}" data-marker-name="{{ site.Title }}"></div>
</div>
</div>
</div>
{{ end }}
{{- end }}
</div>
</div>
</section>
Expand Down
4 changes: 4 additions & 0 deletions layouts/partials/cloak_email.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{{/* Cloak an e-mail address (first argument) */ -}}
{{- $address_parts := split . "@" -}}
{{- if (eq (len $address_parts) 2) -}}
{{- $user := index $address_parts 0 -}}
{{- $domain := index $address_parts 1 -}}
<span class="cloaked-e-mail" data-user="{{ range $index := seq (sub (len $user) 1) 0 }}{{ substr $user $index 1 }}{{ end }}" data-domain="{{ range $index := seq (sub (len $domain) 1) 0 }}{{ substr $domain $index 1 }}{{ end }}"></span>
{{- else -}}
<span>INVALID E-MAIL ADDRESS</span>
{{- end -}}
{{- /* Dummy comment to strip trailing newline */ -}}

0 comments on commit ec7c4b8

Please sign in to comment.