Skip to content

Commit

Permalink
+Added News postings
Browse files Browse the repository at this point in the history
  • Loading branch information
CalGrimes committed Jun 15, 2021
1 parent 3e0e28a commit cf991d1
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = function(eleventyConfig) {

// Alias `layout: post` to `layout: layouts/post.njk`
eleventyConfig.addLayoutAlias("post", "layouts/post.njk");
eleventyConfig.addLayoutAlias("news", "layouts/news.njk");

eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("dd LLL yyyy");
Expand All @@ -43,7 +44,7 @@ module.exports = function(eleventyConfig) {

eleventyConfig.addFilter("filterTagList", tags => {
// should match the list in tags.njk
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
return (tags || []).filter(tag => ["all", "nav", "post", "posts", "news"].indexOf(tag) === -1);
})

// Create an array of all tags
Expand Down
Binary file modified .vs/CalGrimes-Blog-Postings/v16/.suo
Binary file not shown.
Binary file modified .vs/slnx.sqlite
Binary file not shown.
6 changes: 3 additions & 3 deletions _data/metadata.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"title": "Your Blog Name",
"title": "Cal Grimes",
"url": "https://example.com/",
"language": "en",
"description": "I am writing about my experiences as a naval navel-gazer.",
"description": "I am writing about my experiences as a Software Engineer.",
"feed": {
"subtitle": "I am writing about my experiences as a naval navel-gazer.",
"subtitle": "I am writing about my experiences as a Software Engineer.",
"filename": "feed.xml",
"path": "/feed/feed.xml",
"id": "https://example.com/"
Expand Down
2 changes: 2 additions & 0 deletions _includes/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
</div>

<main>
<div class="container">
{{ content | safe }}
</div>
</main>

<footer>
Expand Down
47 changes: 47 additions & 0 deletions _includes/layouts/news.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---

layout: layouts/home.njk
templateClass: tmpl-news
permalink: /news/
eleventyNavigation:
key: News Archive
order: 4
---

<div class="text-center">
<h1>Our News</h1>
<hr>
<br>
</div>
<div class="row">
<div class="col-md-6">
<h1>{{title}}</h1>
<br>
<h5>{{description}}</h5>
</div>
<div class="col-md-6">
<p>Posts tags.</p>
<h3>
{% for tag in tags %}
{%- if collections.tagList.indexOf(tag) != -1 -%}
{% set tagUrl %}/tags/{{ tag }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{%- endif -%}
{% endfor %}
</h3>
<p>See
<a href="{{ '/tags/' | url }}">all tags</a>.</p>
</div>
</div>

<hr>
<br>
<div class="row">
<div class="col-md-6">
{{ content | safe }}
</div>
<div class="col-md-6">
<img src="{{thumbnail}}"/>
</div>
</div>
<hr>
20 changes: 20 additions & 0 deletions _includes/newslist.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<ol reversed="reversed" class="postlist" style="counter-reset: start-from {{ (postslistCounter or postslist.length) + 1 }}">
{% for post in postslist | reverse %}
<li class="postlist-item{% if post.url == url %} postlist-item-active{% endif %}">
<a href="{{ post.url | url }}" class="postlist-link">
{% if post.data.title %}
{{ post.data.title }}
{% else %}
<code>{{ post.url }}</code>
{% endif %}
</a>
<time class="postlist-date" datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate }}</time>
{% for tag in post.data.tags %}
{%- if collections.tagList.indexOf(tag) != -1 -%}
{% set tagUrl %}/tags/{{ tag }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{%- endif -%}
{% endfor %}
</li>
{% endfor %}
</ol>
53 changes: 44 additions & 9 deletions admin/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,49 @@ public_folder: "/images/uploads"
collections:
- name: "blog" # Used in routes, e.g., /admin/collections/blog
label: "Blog" # Used in the UI
folder: "blog" # The path to the folder where the documents are stored - **
folder: "posts" # The path to the folder where the documents are stored
create: true # Allow users to create new documents in this collection
slug: "{{slug}}" # Filename template, e.g., YYYY-MM-DD-title.md - **
slug: "{{slug}}" # Filename template, e.g., YYYY-MM-DD-title.md
fields: # The fields for each document, usually in front matter
- {label: "Layout", name: "layout", widget: "hidden", default: "layouts/post.njk"} # -** can use blog template alias optionally if you set it up previously
- {label: "Tags", name: "tags", widget: "hidden", default: "blog"} # - ** - This is optional
- {label: "Title", name: "title", widget: "string"}
- {label: "Publish Date", name: "date", widget: "datetime"}
- {label: "Featured Image", name: "thumbnail", widget: "image"}
- {label: "Rating (scale of 1-5)", name: "rating", widget: "number"}
- {label: "Body", name: "body", widget: "markdown"}
- {
label: "Layout",
name: "layout",
widget: "hidden",
default: "layouts/post.njk",
}
- { label: "Title", name: "title", widget: "string" }
- { label: "Description", name: "description", widget: "string" }
- {
label: "Tags",
name: "tags",
widget: "list",
field: { label: "Tags", name: "tags", widget: "string" },
}
- { label: "Publish Date", name: "date", widget: "datetime" }
- { label: "Featured Image", name: "thumbnail", widget: "image" }
- { label: "Rating (scale of 1-5)", name: "rating", widget: "hidden" }
- { label: "Body", name: "body", widget: "markdown" }
- name: "news" # Used in routes, e.g., /admin/collections/blog
label: "News" # Used in the UI
folder: "news" # The path to the folder where the documents are stored
create: true # Allow users to create new documents in this collection
slug: "{{slug}}" # Filename template, e.g., YYYY-MM-DD-title.md
fields: # The fields for each document, usually in front matter
- {
label: "Layout",
name: "layout",
widget: "hidden",
default: "layouts/news.njk",
}
- { label: "Title", name: "title", widget: "string" }
- { label: "Description", name: "description", widget: "string" }
- {
label: "Tags",
name: "tags",
widget: "list",
field: { label: "Tags", name: "tags", widget: "string" },
}
- { label: "Publish Date", name: "date", widget: "datetime" }
- { label: "Featured Image", name: "thumbnail", widget: "image" }
- { label: "Rating (scale of 1-5)", name: "rating", widget: "hidden" }
- { label: "Body", name: "body", widget: "markdown" }
29 changes: 25 additions & 4 deletions archive.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@
layout: layouts/home.njk
permalink: /posts/
eleventyNavigation:
key: Archive
key: Blog Archive
order: 2
---

<h1>Archive</h1>
<div class="row">
<div class="col-md-6">
<h1>Blog Archive</h1>
<br>
{% set postslist = collections.posts | head(-50) %}
{% set postslistCounter = collections.posts | length %}
{% include "postslist.njk" %}
</div>

{% set postslist = collections.posts %}
{% include "postslist.njk" %}
<div class="col-md-6">
<div>
<h1>Tags for:
<a href="{{ '/posts/'| url }}" class="post-tag">Blog</a>
</h1>
</div>
<br>
<h1>
{% for tag in collections.tagList %}
{% set tagUrl %}/tags/{{ tag }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{% endfor %}
</h1>

</div>
</div>

0 comments on commit cf991d1

Please sign in to comment.