17Short 短故事

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

  1. 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:

  1. Process all markdown files in the posts/ directory
  2. Extract the most common Chinese words from each post
  3. Add them as tags in the frontmatter
  4. 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

  1. Word Segmentation: Uses jieba to segment Chinese text into words
  2. Keyword Extraction: Uses TF-IDF algorithm to identify important words
  3. Filtering: Removes common stop words and single characters
  4. Frontmatter Update: Updates YAML frontmatter with new tags

Verification

After running the script:

  1. Check a few markdown files to verify tags were added
  2. Run Hugo to build your site:
    hugo server
    
  3. 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"