Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: category/tag support on home page and as separate pages #393

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ You have two options for the list of blog posts on the home page:
show_all_posts: true
```


### Category and Tag section on home page
You can show a category and tag section on the home page by editing the hexo ```_config.yml``` file.

```yml
# Show a Tags section on the home page
show_tags_section: true

# Show a Category section on the home page
show_category_section: true
```
The theme has a provision to make separate tags and category pages. For this, you need to follow these steps:
- make a new hexo page.
- changing the layout to ```tags``` for a tags page or ```categories``` for a categories page.
- adding the relevant paths in your nav menu.

### Projects list

Create a projects file `source/_data/projects.json` to show a list of your projects on the index page.
Expand Down
5 changes: 5 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ nav:
articles: /archives/
projects: http://github.com/probberechts

# Show a Tags section on the home page
show_tags_section: true

# Show a Category section on the home page
show_category_section: true

# Links to your social media accounts.
# The 'icon' keys should correspond to Fontawesome icon names
Expand Down
26 changes: 26 additions & 0 deletions layout/categories.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%- partial('_partial/head') %>
<div class="page">
<div class="post-list">
<span class="h1"><a href="<%- url_for('/categories') %>">Categories</a></span>
a category wise display of posts
<% if (site.categories && site.categories.length > 0) { %>
<ul class="category-list">
<% site.categories.forEach(function(category){ %>
<li class="category">
<b><a href="<%= url_for(category.path) %>"><%= category.name %></a></b> (<%= category.length %>)
<ul class="post-list">
<% category.posts.forEach(function(post){ %>
<li>
<a href="<%= url_for(post.path) %>"><%= post.title %></a>
</li>
<% }) %>
</ul>
</li><br />
<% }) %>
</ul>
<% } else { %>
<p>No categories found.</p>
<% } %>
</div>
</div>
<%- partial('_partial/footer') %>
34 changes: 34 additions & 0 deletions layout/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,37 @@
</ul>
</section>
<% } %>

<% if (theme.show_tags_section) { %>
<section id="tags">
<span class="h1"><a href="<%- url_for('/tags') %>">Tags</a></span>
<% if (site.tags && site.tags.length > 0) { %>
<ul class="tag-list">
<% site.tags.forEach(function(tag){ %>
<li class="tag">
<a href="<%= url_for(tag.path) %>"><%= tag.name %></a> (<%= tag.length %>)
</li>
<% }) %>
</ul>
<% } else { %>
<p>No tags found.</p>
<% } %>
</section>
<% } %>

<% if (theme.show_category_section) { %>
<section id="categories">
<span class="h1"><a href="<%- url_for('/categories') %>">Categories</a></span>
<% if (site.categories && site.categories.length > 0) { %>
<ul class="category-list">
<% site.categories.forEach(function(category){ %>
<li class="category">
<a href="<%= url_for(category.path) %>"><%= category.name %></a> (<%= category.length %>)
</li>
<% }) %>
</ul>
<% } else { %>
<p>No categories found.</p>
<% } %>
</section>
<% } %>
26 changes: 26 additions & 0 deletions layout/tags.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%- partial('_partial/head') %>
<div class="page">
<div class="post-list">
<span class="h1"><a href="<%- url_for('/tags') %>">Tags</a></span>
a tag wise display of posts
<% if (site.tags && site.tags.length > 0) { %>
<ul class="tag-list">
<% site.tags.forEach(function(tag){ %>
<li class="tag">
<b><a href="<%= url_for(tag.path) %>"><%= tag.name %></a></b> (<%= tag.length %>)
<ul class="post-list">
<% tag.posts.forEach(function(post){ %>
<li>
<a href="<%= url_for(post.path) %>"><%= post.title %></a>
</li>
<% }) %>
</ul>
</li><br />
<% }) %>
</ul>
<% } else { %>
<p>No tags found.</p>
<% } %>
</div>
</div>
<%- partial('_partial/footer') %>