Skip to content

Commit

Permalink
Include category pages, links
Browse files Browse the repository at this point in the history
  • Loading branch information
fongandrew committed Jun 1, 2017
1 parent 63371e7 commit 4b2fa18
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 21 deletions.
15 changes: 13 additions & 2 deletions _includes/sidebar.html
Expand Up @@ -15,9 +15,8 @@ <h1>

{% comment %}
The code below dynamically generates a sidebar nav of pages with
`layout: page` in the front-matter. See readme for usage.
`sidebar_link: true` in the front-matter. See readme for usage.
{% endcomment %}

{% assign pages_list = site.pages %}
{% for node in pages_list %}
{% if node.title != null %}
Expand All @@ -27,6 +26,18 @@ <h1>
{% endif %}
{% endif %}
{% endfor %}

{% comment %}
Now do it again, but for category pages
{% endcomment %}
{% for node in pages_list %}
{% if node.title != null %}
{% if node.layout == "category" %}
<a class="sidebar-nav-item{% if page.url == node.url %} active{% endif %}"
href="{{ site.baseurl }}{{ node.url }}">{{ node.title }}</a>
{% endif %}
{% endif %}
{% endfor %}
<span class="sidebar-nav-item">Currently v{{ site.version }}</span>
</nav>

Expand Down
21 changes: 21 additions & 0 deletions _layouts/category.html
@@ -0,0 +1,21 @@
---
layout: page
---

{% unless page.content == '' %}
{{ content }}
{% endunless %}

<ul class="posts-list">
{% assign category = page.category | default: page.title %}
{% for post in site.categories[category] %}
<li>
<h3>
<a href="{{ site.baseurl }}{{ post.url }}">
{{ post.title }}
<small>{{ post.date | date_to_string }}</small>
</a>
</h3>
</li>
{% endfor %}
</ul>
37 changes: 34 additions & 3 deletions _layouts/post.html
Expand Up @@ -4,14 +4,45 @@

<div class="post">
<h1 class="post-title">{{ page.title }}</h1>
<span class="post-date">{{ page.date | date_to_string }}</span>
<div class="post-meta">
<span class="post-date">{{ page.date | date_to_string }}</span>
<span class="post-categories">
{% for category in page.categories %}
&bull;

{% comment %}
Check if this category has a corresponding page before decide
to link to it. This is an O(n^2) operations so consider removing
it and linking for all categories (or no categories) if this
site has a lot of pages and/or a lot of categories.
{% endcomment %}
{% assign category_page = false %}
{% for node in site.pages %}
{{ node.category }}
{% if node.category == category or node.title == category %}
{% assign category_page = node %}
{% endif %}
{% endfor %}

{% if category_page %}
<a href="{{ site.baseurl }}{{ category_page.url }}">
{{ category }}
</a>
{% else %}
{{ category }}
{% endif %}
{% endfor %}
</span>
</div>

{{ content }}

<div class="post-tags">
{% for tag in page.tags %}
<a href="{{ site.baseurl }}/tags#{{ tag | slugify }}">
<span class="icon">{% include svg/tags.svg %}</span>
<span class="tag-name">{{ tag }}</span>
<span class="icon">
{% include svg/tags.svg %}
</span>&nbsp;<span class="tag-name">{{ tag }}</span>
</a>
{% endfor %}
</div>
Expand Down
2 changes: 2 additions & 0 deletions _posts/2012-01-29-markup-text-readability.md
Expand Up @@ -2,6 +2,8 @@
layout: post
title: "Markup: Text Readability Test"
excerpt: "A large amount of sample text to test readability of a text heavy page."
categories:
- Markup
tags:
- sample post
- readability
Expand Down
2 changes: 1 addition & 1 deletion _posts/2012-01-30-markup-title-with-markup.md
Expand Up @@ -2,7 +2,7 @@
layout: post
title: "Markup: Title *with* **Markdown**"
categories:
- Markdown
- Markup
tags:
- css
- html
Expand Down
15 changes: 13 additions & 2 deletions _sass/_posts.scss
Expand Up @@ -24,13 +24,24 @@
}

// Meta data line below post title
.post-date {
display: block;
.post-meta {
margin-top: -.5rem;
margin-bottom: 1rem;
color: #9a9a9a;
}

.post-tags a {
font-size: 0.8em;
margin-right: 0.5rem;
white-space:nowrap;
.tag-name { text-transform: capitalize; }

opacity: 0.75;
&:hover {
text-decoration: none;
opacity: 1;
}
}

// Related posts
.related {
Expand Down
13 changes: 0 additions & 13 deletions _sass/_tags.scss
Expand Up @@ -21,16 +21,3 @@
}
}
}

.post-tags a {
font-size: 0.8em;
margin-right: 0.5rem;
white-space:nowrap;
.tag-name { text-transform: capitalize; }

opacity: 0.75;
&:hover {
text-decoration: none;
opacity: 1;
}
}
27 changes: 27 additions & 0 deletions category/edge-case.md
@@ -0,0 +1,27 @@
---
layout: category
title: Edge Case
---

Sample category page. You need to create a page for each category.
The category is inferred from the title of the page, but you can also
specify it with the `category` attribute in the front matter.

```md
---
layout: category
title: My Category
---
```

Or ...

```md
---
layout: category
title: Fancy Tital
category: My Category
---
```

Posts get listed below here.
6 changes: 6 additions & 0 deletions category/markup.md
@@ -0,0 +1,6 @@
---
layout: category
title: Markup
---

Another sample category page.

0 comments on commit 4b2fa18

Please sign in to comment.