Skip to content

Commit

Permalink
add tag page
Browse files Browse the repository at this point in the history
  • Loading branch information
wh.huajieyu committed May 14, 2024
1 parent 0c7b71f commit 57c3b36
Show file tree
Hide file tree
Showing 24 changed files with 174 additions and 3 deletions.
5 changes: 4 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ collections:
category:
output: true
permalink: /category/:slug/
tag:
output: true
permalink: /tag/:tag/

#baseurl: ""
# permalink: /blog/:slug
Expand All @@ -53,7 +56,7 @@ About: /about
# Add general links to site pages here
links:
Resume: /assets/resume.pdf


# Add links for more focus here
special_links:
Expand Down
2 changes: 1 addition & 1 deletion _includes/back_link.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<a href="{{ "/" | relative_url }}">{{ site.theme_config.back_home_text }}</a>
<a href="javascript:history.back(-1)">{{ site.theme_config.back_home_text }}</a>
18 changes: 18 additions & 0 deletions _includes/collecttags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% assign rawtags = "" %}
{% for post in site.posts %}
{% assign ttags = post.tags | join:'|' | append:'|' %}
{% assign rawtags = rawtags | append:ttags %}
{% endfor %}
{% assign rawtags = rawtags | split:'|' | sort %}

{% assign site.tags = "" %}
{% for tag in rawtags %}
{% if tag != "" %}
{% if tags == "" %}
{% assign tags = tag | split:'|' %}
{% endif %}
{% unless tags contains tag %}
{% assign tags = tags | join:'|' | append:'|' | append:tag | split:'|' %}
{% endunless %}
{% endif %}
{% endfor %}
4 changes: 3 additions & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
<link rel="shortcut icon" type="image/x-icon" href="{{ "/assets/favicon.ico" | relative_url }}" />
<link rel="stylesheet" href="{{ "/css/main.css" | relative_url }}" />
<link rel="stylesheet" href="{{ "/assets/vs.css" | relative_url }}" />

{% if site.tags != "" %}
{% include collecttags.html %}
{% endif %}
</head>
7 changes: 7 additions & 0 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ <h1>{{ page.title }}</h1>
{{ content }}
</article>

<span>Tags: [
{% for tag in page.tags %}
{% capture tag_name %}{{ tag }}{% endcapture %}
<a href="/tag/{{ tag_name }}"><code class="highligher-rouge"><nobr>{{ tag_name }}</nobr></code>&nbsp;</a>
{% endfor %}
]</span>

<script
src="https://giscus.app/client.js"
data-repo="AlexVagrant/AlexVagrant.github.io"
Expand Down
15 changes: 15 additions & 0 deletions _layouts/tag.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: default
---
{%-include back_link.html-%}
<div class="post">
<h1>Tag: {{ page.tag }}</h1>
<ul>
{% for post in site.tags[page.tag] %}
<li><a href="{{ post.url }}">{{ post.title }}</a> ({{ post.date | date_to_string }})<br>
{{ post.description }}
</li>
{% endfor %}
</ul>
</div>
<hr>
15 changes: 15 additions & 0 deletions api/post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: null
permalink: /api/post.json
---
[
{% for post in site.posts %}{
"title": {{ post.title | jsonify }},
"url": {{ post.url | jsonify }},
"category": {{ post.category | jsonify }},
"date": {{ post.date | jsonify }},
"tags": {{ post.tags | jsonify }}
}{% unless forloop.last %},{% endunless %}

{% endfor %}
]
9 changes: 9 additions & 0 deletions api/tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
layout: null
permalink: /api/tags.json
---
{
{% for tag in site.tags %}
{{tag[0] | jsonify}}: {{tag[1].size | jsonify}}{% unless forloop.last %},{% endunless %}
{% endfor %}
}
27 changes: 27 additions & 0 deletions generateTag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import requests
import os

tags_get = requests.get('http://127.0.0.1:4000/api/tags.json')
tags = tags_get.json()

# for tag in tags:
# print(tag+':',tags[tag])

build_tags = [tag for tag in tags]

for root, dirs, files in os.walk('./tag'):
for file_name in files:
tag = file_name[:-3]
if tag in tags and tag in build_tags:
build_tags.remove(tag)
print("Building new tags:", build_tags)

tag_pattern = '---\n'
tag_pattern += 'layout: tag\n'
tag_pattern += 'title: %s\n'
tag_pattern += 'tag: %s\n'
tag_pattern += '---\n'

for tag in build_tags:
with open('./tag/'+tag+'.md', 'w') as f:
f.write(tag_pattern % (tag, tag))
5 changes: 5 additions & 0 deletions tag/Firefox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: Firefox
tag: Firefox
---
5 changes: 5 additions & 0 deletions tag/algorithm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: algorithm
tag: algorithm
---
5 changes: 5 additions & 0 deletions tag/binary_tree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: binary_tree
tag: binary_tree
---
5 changes: 5 additions & 0 deletions tag/blog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: blog
tag: blog
---
5 changes: 5 additions & 0 deletions tag/clipboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: clipboard
tag: clipboard
---
5 changes: 5 additions & 0 deletions tag/debugger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: debugger
tag: debugger
---
5 changes: 5 additions & 0 deletions tag/git.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: git
tag: git
---
5 changes: 5 additions & 0 deletions tag/html2canvas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: html2canvas
tag: html2canvas
---
5 changes: 5 additions & 0 deletions tag/linklist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: linklist
tag: linklist
---
5 changes: 5 additions & 0 deletions tag/pnpm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: pnpm
tag: pnpm
---
5 changes: 5 additions & 0 deletions tag/prime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: prime
tag: prime
---
5 changes: 5 additions & 0 deletions tag/quick_sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: quick_sort
tag: quick_sort
---
5 changes: 5 additions & 0 deletions tag/safearea.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: safearea
tag: safearea
---
5 changes: 5 additions & 0 deletions tag/shortest_path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: shortest_path
tag: shortest_path
---
5 changes: 5 additions & 0 deletions tag/vscode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: tag
title: vscode
tag: vscode
---

0 comments on commit 57c3b36

Please sign in to comment.