Skip to content

Commit

Permalink
Contact form and Google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
alanta committed Nov 20, 2020
1 parent 99f10ef commit 0e05b1f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 31 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Theme License: MIT (https://bootstrapstarter.com/license/)
Credits:
- Letter PNG Designed By starwash from <a href="https://pngtree.com/">Pngtree.com</a>
- Bootstrap, licensed MIT, docs CC BY 3.0.
- Unsplash images.
- Unsplash images and Pexels
2 changes: 2 additions & 0 deletions Models/SiteSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public class SiteSettings{
public string Copyright { get; set; }
public bool AuthorBox { get; set; }
public string DisqusId { get; set; }
public string ContactFormUrl { get; set; }
public string? GoogleAnalytics { get; set; }
}
}
11 changes: 10 additions & 1 deletion Pipelines/Pages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Pages(IDeliveryClient deliveryClient, SiteSettings site)

ProcessModules = new ModuleList
{
new MergeContent(new ReadFiles(patterns: "Page.cshtml")),
new MergeContent(new ReadFiles( KontentConfig.Get<Page,string>( ViewForPage))),
new RenderRazor()
.WithViewData("Title", KontentConfig.Get<Page,string>( p => p.Title ))
.WithViewData("SiteMetadata", site)
Expand All @@ -51,6 +51,15 @@ public Pages(IDeliveryClient deliveryClient, SiteSettings site)
new WriteFiles(),
};
}

public string ViewForPage(Page page)
{
return page.System.Codename switch
{
"contact" => "Contact.cshtml",
_ => "Page.cshtml"
};
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"Favicon": "assets/images/logo.png",
"Copyright": "Memoirs",
"lazyimages": false,
"authorbox": true
"authorbox": true,
"contactFormUrl": "https://formspree.io/f/maylbkgo",
"GoogleAnalytics": ""
}
}
10 changes: 0 additions & 10 deletions changelog.md

This file was deleted.

13 changes: 13 additions & 0 deletions input/Shared/contact.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<form action="@Html.Site().ContactFormUrl" method="POST">
<p class="mb-4">Please send your message to @Html.Site().Name. We will reply as soon as possible!</p>
<div class="form-group row">
<div class="col-md-6">
<input class="form-control" type="text" name="name" placeholder="Name*" required>
</div>
<div class="col-md-6">
<input class="form-control" type="email" name="_replyto" placeholder="E-mail Address*" required>
</div>
</div>
<textarea rows="8" class="form-control mb-3" name="message" placeholder="Message*" required></textarea>
<input class="btn btn-dark" type="submit" value="Send">
</form>
30 changes: 14 additions & 16 deletions input/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@

</head>

@*{% if jekyll.environment == 'production' %}
<!-- change your GA id in _config.yml -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '{{site.google_analytics}}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}*@

@*{% capture layout %}{% if page.layout %}layout-{{ page.layout }}{% endif %}{% endcapture %}*@
@if( !string.IsNullOrWhiteSpace(Html.Site().GoogleAnalytics) ){
<!-- change your GA id in appsettings.json -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '@Html.Site().GoogleAnalytics', 'auto');
ga('send', 'pageview');
</script>
}
<body>
<!-- defer loading of font and font awesome -->
<noscript id="deferred-styles">
Expand All @@ -56,9 +54,9 @@
<ul>
<h3>Navigation</h3>
<li><a href="@Html.GetLink("/")">Home</a></li>
<li><a href="@Html.GetLink("/about")">About <span class="badge badge-primary">Memoirs Jekyll Theme</span></a></li>
<li><a target="_blank" href="https://bootstrapstarter.com/bootstrap-templates/jekyll-theme-memoirs/">Get Memoirs</a></li>
<li><a href="@Html.GetLink("/contact")">Contact</a></li>
<li><a href="@Html.GetLink("/about.html")">About <span class="badge badge-primary">Memoirs Jekyll Theme</span></a></li>
<li><a target="_blank" href="https://github.com/alanta/Memoirs-Theme">Get Memoirs</a></li>
<li><a href="@Html.GetLink("/contact.html")">Contact</a></li>
</ul>
</nav>
<partial name="Shared/search-lunr"/>
Expand Down
10 changes: 8 additions & 2 deletions input/page.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
<partial name="Shared/_featured-image" model="Model.Image"/>

<!-- Content -->
<partial name="Shared/_article" model="Model" />
<partial name="Shared/_article" model="Model"/>

@if (Model.System.Codename == "contact")
{
// render contact form
<partial name="Shared/contact"/>
}

<!-- Comments if not disabled with comments: false -->
{% include comments.html %}
<partial name="Shared/comments" model="Model"/>

0 comments on commit 0e05b1f

Please sign in to comment.