Tag-Based Related Posts
Simple, Reliable Content Discovery
XenT’s related posts system uses tag and category similarity to recommend relevant content. This approach is:
- Fast: No network requests or external APIs
- Reliable: Works offline and never fails builds
- Transparent: Users understand why posts are related
- Zero-config: Works immediately with your existing tags
How It Works
The system calculates similarity between posts using the Jaccard index:
similarity = |tags_A ∩ tags_B| / |tags_A ∪ tags_B|
For example:
- Post A:
['typescript', 'react', 'hooks'] - Post B:
['react', 'hooks', 'testing'] - Similarity:
2/4 = 0.5(50% similarity)
Configuration
Enable related posts in your config:
// user.config.ts
export default defineConfig({
content: {
relatedPosts: {
enabled: true,
maxPosts: 3, // Number of related posts to show
minSimilarity: 0.1, // Minimum similarity threshold
},
},
});
Configuration Options
| Option | Default | Description |
|---|---|---|
enabled | true | Enable/disable related posts |
maxPosts | 3 | Maximum number of related posts to display |
minSimilarity | 0.1 | Minimum similarity score (0-1) to show a post |
How Posts Are Selected
- Calculate similarity with current post’s tags and categories
- Filter by threshold - only posts above
minSimilarity - Sort by score - highest similarity first
- Take top N - limited by
maxPosts - Fallback to recent - if no similar posts found
Best Practices
Tagging Strategy
- Use consistent tags across related posts
- 3-5 tags per post works best
- Mix specific (
react-hooks) and general (javascript) tags - Use categories for broader groupings
Example Tag Structure
// Good tagging for discoverability
{
title: "Advanced React Hooks",
tags: ['react', 'hooks', 'javascript', 'frontend'],
categories: ['Development']
}
{
title: "Testing React Hooks",
tags: ['react', 'hooks', 'testing', 'jest'],
categories: ['Development']
}
// These posts will have 50% similarity (2/4 shared tags)
Implementation Details
The related posts system uses:
- Jaccard similarity for robust tag matching
- Case-insensitive comparison for consistency
- Combined tags and categories for richer matching
- Recent posts fallback when no similar content exists
Performance
- Build time: Negligible impact (milliseconds)
- Runtime: Fast in-memory calculations
- Bundle size: ~1KB additional JavaScript
- Dependencies: Zero external dependencies
Comparison with AI Embeddings
| Feature | Tag-Based | AI Embeddings |
|---|---|---|
| Setup | Zero config | API keys, providers |
| Build time | Instant | Minutes (network calls) |
| Reliability | 100% | Depends on API uptime |
| Cost | Free | API costs per request |
| Transparency | Clear why posts match | Black box recommendations |
| Offline | Yes | No |
Advanced Usage
Custom Similarity Logic
For special cases, you can extend the related posts utility:
// src/utils/customRelatedPosts.ts
import { getRelatedPosts } from '@/utils/relatedPosts';
export function getRelatedPostsWithBoost(post, allPosts) {
const related = getRelatedPosts(post, allPosts);
// Boost posts in same category
return related.sort((a, b) => {
const aBoost = a.data.categories?.includes(post.data.categories?.[0]) ? 0.1 : 0;
const bBoost = b.data.categories?.includes(post.data.categories?.[0]) ? 0.1 : 0;
return bBoost - aBoost;
});
}
Tag Cloud Integration
Related posts work naturally with tag clouds:
// Get posts by specific tags
import { getPostsByTags } from '@/utils/relatedPosts';
const reactPosts = getPostsByTags(['react'], allPosts);
Migration from AI Embeddings
If you’re coming from the AI embedding system:
- No config changes needed - tag-based system uses same settings
- Performance improvement - builds will be significantly faster
- No API setup required - remove embedding provider configuration
- Better transparency - users can see tag relationships
Troubleshooting
No Related Posts Showing
- Check tags: Ensure posts have overlapping tags
- Lower threshold: Reduce
minSimilarityin config - Add more tags: Use 3-5 relevant tags per post
- Check categories: Categories count as tags for similarity
Too Many/Few Related Posts
- Too many: Increase
minSimilarityor reducemaxPosts - Too few: Decrease
minSimilarityor add more tags to posts
The tag-based system provides reliable, fast content discovery that scales with your blog without external dependencies.