Replaces tag index plugin with native jekyll features (#307)

* remove tag _gen plugin and its folder

* remove deprecated tag index layout

* add tag index page

* link tag index page in nav bar, enable tag links by default

* add button spacer in main css

* fix tag links in post view

* fix tag links on index and pagination

* tag link instuctions removed. it's enabled as default
This commit is contained in:
OCram85 2018-01-19 05:58:00 +01:00 committed by Dean Attali
parent 22e77cff59
commit 3664e56dbd
8 changed files with 50 additions and 88 deletions

View File

@ -240,8 +240,6 @@ Whenever you make any changes to `_config.yml`, you must stop and re-start the s
Disclaimer: I personally am NOT using local development so I don't know much about running Jekyll locally. If you follow this route, please don't ask me questions because unfortunately I honestly won't be able to help!
Aditionally, if you choose to deploy Jekyll using a local ruby installation, you can tell Jekyll to automatically categorize your blog posts by tags. You just need to set `link-tags: true` in `_config.yml`. Jekyll will then generate a new page for each unique tag which lists all of the posts that belong to that tag.
## FAQ
Beautiful Jekyll is actively used by thousands of people with wildly varying degrees of competency, so it's impossible to answer all the questions that may arise. Below are answers to a few very common questions. Most questions that I get asked are not directly related to this theme, and instead are more general questions about Jekyll or web development. Many such questions can be answered by reading the [Jekyll documentation](http://jekyllrb.com/) or simply by Googling.

View File

@ -29,6 +29,7 @@ navbar-links:
- Learn markdown: "http://www.markdowntutorial.com/"
- GitHub Pages: "https://pages.github.com/"
Author's home: "http://deanattali.com"
Tags: "tags"
# Image to show in the navigation bar - image must be a square (width = height)
# Remove this parameter if you don't want an image in the navbar
@ -152,7 +153,7 @@ defaults:
show-avatar: true
# Use tags pages (not recommended if you are deploying via GitHub pages, only set to true if deploying locally with ruby)
link-tags: false
link-tags: true
# Exclude these files from production site
exclude:

View File

@ -40,7 +40,7 @@ layout: base
Tags:
{% if site.link-tags %}
{% for tag in page.tags %}
<a href="/tag/{{ tag }}">{{ tag }}</a>
<a href="{{ site.baseurl }}/tags#{{- tag -}}">{{- tag -}}</a>
{% endfor %}
{% else %}
{{ page.tags | join: ", " }}

View File

@ -1,41 +0,0 @@
---
layout: default
---
<h2 class="post_title">{{page.title}}:</h2>
<div class="posts-list">
{% for post in site.posts %}
{% for tag in post.tags %}
{% if tag == page.tag %}
<article class="post-preview">
<a href="{{ post.url | prepend: site.baseurl }}">
<h3 class="post-title">{{ post.title }}</h3>
{% if post.subtitle %}
<h4 class="post-subtitle">
{{ post.subtitle }}
</h4>
{% endif %}
</a>
<p class="post-meta">
Posted on {{ post.date | date: "%B %-d, %Y" }}
</p>
<div class="post-entry">
{{ post.content | strip_html | xml_escape | truncatewords: 50 }}
<a href="{{ post.url | prepend: site.baseurl }}" class="post-read-more">[Read&nbsp;More]</a>
</div>
<div class="blog-tags">
Tags:
{% for tag in post.tags %}
<a href="/tag/{{ tag }}">{{ tag }}</a>
{% endfor %}
</div>
</article>
{% endif %}
{% endfor %}
{% endfor %}
</div>

View File

@ -1,33 +0,0 @@
module Jekyll
class TagIndex < Page
def initialize(site, base, dir, tag)
@site = site
@base = base
@dir = dir
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
self.data['tag'] = tag
tag_title_prefix = site.config['tag_title_prefix'] || 'Posts Tagged &ldquo;'
tag_title_suffix = site.config['tag_title_suffix'] || '&rdquo;'
self.data['title'] = "#{tag_title_prefix}#{tag}#{tag_title_suffix}"
end
end
class TagGenerator < Generator
safe true
def generate(site)
if site.layouts.key? 'tag_index'
dir = site.config['tag_dir'] || 'tag'
site.tags.keys.each do |tag|
write_tag_index(site, File.join(dir, tag), tag)
end
end
end
def write_tag_index(site, dir, tag)
index = TagIndex.new(site, site.source, dir, tag)
index.render(site.layouts, site.site_payload)
index.write(site.dest)
site.pages << index
end
end
end

View File

@ -743,3 +743,9 @@ td.gutter {
.navbar-default button.navbar-toggle[aria-expanded="true"] {
background-color: rgba(0, 0, 0, 0.2);
}
/* fix btn spacing in tag index */
.tag-btn {
margin: 5px;
}

View File

@ -44,7 +44,7 @@ use-site-title: true
Tags:
{% if site.link-tags %}
{% for tag in post.tags %}
<a href="{{ site.baseurl }}/tag/{{ tag }}">{{ tag }}</a>
<a href="{{ site.baseurl }}/tags#{{- tag -}}">{{- tag -}}</a>
{% endfor %}
{% else %}
{{ post.tags | join: ", " }}

31
tags.html Normal file
View File

@ -0,0 +1,31 @@
---
layout: page
title: 'Tag Index'
---
{%- capture site_tags -%}
{%- for tag in site.tags -%}
{{- tag | first -}}{%- unless forloop.last -%},{%- endunless -%}
{%- endfor -%}
{%- endcapture -%}
{%- assign tags_list = site_tags | split:',' | sort -%}
{%- for tag in tags_list -%}
<a href="#{{- tag -}}" class="btn btn-primary tag-btn"><i class="fa fa-tag" aria-hidden="true"></i>&nbsp;{{- tag -}}</a>
{%- endfor -%}
{%- for tag in tags_list -%}
<h3 id="{{- tag -}}"><i class="fa fa-tag" aria-hidden="true"></i>&nbsp;{{- tag -}}</h3>
<ul class="post-list">
{%- for post in site.tags[tag] -%}
<li>
<i class="fa fa-calendar-check-o" aria-hidden="true"></i>&nbsp;
<span class="entry-date">
<time datetime="{{- post.date | date_to_xmlschema -}}">{{- post.date | date: "%B %d, %Y" -}}</time>
</span>
<i class="fa fa-newspaper-o" aria-hidden="true"></i>&nbsp;
<a href="{{- site.url -}}{{- post.url -}}">{{- post.title -}}</a>
</li>
{%- endfor -%}
</ul>
{%- endfor -%}