diff options
author | David Döring <david.doering@knopf-und-wolle.de> | 2020-08-12 00:36:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-12 00:36:22 +0300 |
commit | 1423be6a0b5db3a7d1445b4379fa7cd16ae8d0d6 (patch) | |
tree | 3d407a87afd7a31e964d6964a04636e0a5e52884 | |
parent | 1f5acafabe498e0aa5f3ef7ce4b9825b76122876 (diff) |
Add .Title of subpage to <title> tag in head, if given (#30)20200812
* add .Title of subpage to <title> tag in head, if given
Search rankings use various metrics. One of them commonly is the diversity of <title>-Tags throughout the whole page. Therefore we should make sure every page on your site has a title specified in the <title> tag.
https://support.google.com/webmasters/answer/35624
Since this theme already uses a title-property for every content-page, these titles can also be used in the <title>-Tag.
* Added functionality to send Mails through raw PHP.
The user needs to set "service" to "php" and configure the correct addresses in "static/contact_mail.php".
-rw-r--r-- | exampleSite/config.toml | 5 | ||||
-rw-r--r-- | exampleSite/static/contact_mail.php | 37 | ||||
-rw-r--r-- | layouts/partials/contact.html | 55 | ||||
-rw-r--r-- | layouts/partials/header.html | 2 |
4 files changed, 80 insertions, 19 deletions
diff --git a/exampleSite/config.toml b/exampleSite/config.toml index bc4eee8..0d177bf 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -126,12 +126,15 @@ unsafe = true [params.contact] #Use this section to automate contact form. - #Set service to either "netlify" or "formspree" + #Set service to either "netlify", "formspree" or "php" #For formspree, please setup an account at https://formspree.io/ #For netlify, please read https://www.netlify.com/docs/form-handling/ # #If you use netlify, you'll need to set the confirm_page value (or else users will see a generic netlify response) #If you use formspree, you'll need to set your formspree email address. + # + #If you use php, you need to host this site on a Server capable of running php. + # Please edit the /static/contact_mail.php file from the exampleSite. service = "netlify" confirm_page = "/contact_thanks" # formspree_email="" diff --git a/exampleSite/static/contact_mail.php b/exampleSite/static/contact_mail.php new file mode 100644 index 0000000..755f34f --- /dev/null +++ b/exampleSite/static/contact_mail.php @@ -0,0 +1,37 @@ +<?php +# Edit the following 5 variables to fit your needs! + +# Recipient of the Mail: +$to = "admin@example.org"; +# The "from" address of the Mail. This should match the domain of the server: +$from = "website@example.org"; +# Forward Users to this Page if the mail is successfully sent: +$confirm_page = "/contact_thanks"; +# If something goes wrong and sending the mail fails, forward users to: +$error_page = "/404.html"; +# Specify the Subject of the Mail: +$subject = "Feedback from example.org"; + + +if (isset($_POST['send'])) { + $message = "Name: " . $_POST['name'] . "\r\n\r\n"; + $message .= "Email: " . $_POST['email'] . "\r\n\r\n"; + $message .= "Message: " . $_POST['message'] . "\r\n\r\n"; + + $headers = "From: " . $from . "\r\n"; + $headers .= "Content-Type: text/plain; charset: utf-8"; + $email_ok = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); + if ($email_ok) { + $headers .= "\r\nReply-To: $email"; + } + + $success = mail($to, $subject, $message, $headers); + + if (isset($success) && $success){ + header("Location: ".$confirm_page); + exit; + } +} +header("Location: ".$error_page); +exit; +?>
\ No newline at end of file diff --git a/layouts/partials/contact.html b/layouts/partials/contact.html index d907219..5632339 100644 --- a/layouts/partials/contact.html +++ b/layouts/partials/contact.html @@ -48,22 +48,43 @@ </div>
</form>
{{ else if eq .Site.Params.Contact.service "formspree" }}
- <form method="POST" action="https://formspree.io/{{ .Site.Params.Contact.formspree_email }}">
- <div class="row gtr-50 gtr-uniform">
- <div class="col-6 col-12-mobilep">
- <input type="text" name="name" id="name" value="" aria-label="Name" placeholder="Name" />
- </div>
- <div class="col-6 col-12-mobilep">
- <input type="email" name="_replyto" id="email" value="" aria-label="Email" placeholder="Email" />
- </div>
- <div class="col-12">
- <textarea name="message" id="message" aria-label="Enter your message" placeholder="Enter your message" rows="6"></textarea>
- </div>
- <div class="col-12">
- <ul class="actions special">
- <li><input type="submit" value="Send Message" /></li>
- </ul>
- </div>
+ <form method="POST" action="https://formspree.io/{{ .Site.Params.Contact.formspree_email }}">
+ <div class="row gtr-50 gtr-uniform">
+ <div class="col-6 col-12-mobilep">
+ <input type="text" name="name" id="name" value="" aria-label="Name" placeholder="Name" />
+ </div>
+ <div class="col-6 col-12-mobilep">
+ <input type="email" name="_replyto" id="email" value="" aria-label="Email" placeholder="Email" />
+ </div>
+ <div class="col-12">
+ <textarea name="message" id="message" aria-label="Enter your message" placeholder="Enter your message" rows="6"></textarea>
+ </div>
+ <div class="col-12">
+ <ul class="actions special">
+ <li><input type="submit" value="Send Message" /></li>
+ </ul>
</div>
- </form>
+ </div>
+ </form>
+{{ else if eq .Site.Params.Contact.service "php" }}
+ <form name="contact" method="POST" action="/contact_mail.php" netlify>
+ <div class="row gtr-50 gtr-uniform">
+ <div class="col-6 col-12-mobilep">
+ <input type="text" name="name" aria-label="Your name" placeholder="Your name">
+ </div>
+ <div class="col-6 col-12-mobilep">
+ <input type="email" name="email" aria-label="Email address" placeholder = "Email address">
+ </div>
+ <div class="col-12">
+ <textarea name="message" aria-label="Enter your message" placeholder="Enter your message" rows="6"></textarea>
+ </div>
+ <div class="col-12">
+ <ul class="actions special">
+ <li>
+ <input type="submit" value="Send" name="send"/>
+ </li>
+ </ul>
+ </div>
+ </div>
+ </form>
{{ end }}
diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 2578736..497d902 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -1,7 +1,7 @@ <!DOCTYPE HTML> {{ with .Site.Params.languageCode }}<html lang="{{ . }}">{{ end }} <head> - <title>{{ .Site.Params.title }}</title> + <title>{{ if .Title }}{{ .Title }} | {{ end }} {{ .Site.Params.title }}</title> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> {{ with .Site.Params.subtitle }}<meta name="description" content="{{ . }}">{{ end }} |