Tag Generation for Hugo Site
This directory contains a Python script that automatically generates tags for your markdown posts based on common Chinese words.
Setup
- Install Python dependencies:
pip install -r requirements.txt
Or the script will automatically install jieba
if not found.
Usage
Run the script from the content directory:
cd content
python generate_tags.py
The script will:
- Process all markdown files in the
posts/
directory - Extract the most common Chinese words from each post
- Add them as tags in the frontmatter
- Display statistics about the most common tags
Configuration
You can adjust the script parameters:
top_n_tags
: Number of tags to add per post (default: 8)STOP_WORDS
: Set of words to exclude from tags
How It Works
- Word Segmentation: Uses jieba to segment Chinese text into words
- Keyword Extraction: Uses TF-IDF algorithm to identify important words
- Filtering: Removes common stop words and single characters
- Frontmatter Update: Updates YAML frontmatter with new tags
Verification
After running the script:
- Check a few markdown files to verify tags were added
- Run Hugo to build your site:
hugo server
- Visit your homepage to see the tag cloud
Tag Cloud Display
The tag cloud is configured in layouts/_default/home.html
and will:
- Show all tags with post counts
- Size tags based on frequency (more posts = larger size)
- Link to tag pages showing all posts with that tag
Configuration Files
Make sure these files are properly configured:
hugo.toml
[taxonomies]
tag = "tags"
category = "categories"
configTaxo.toml
[taxonomies]
tag = "tags"
category = "categories"