fresh-main #3
|
@ -11,6 +11,9 @@ tags:
|
||||||
- ci-cd
|
- ci-cd
|
||||||
- automation
|
- automation
|
||||||
readTime: 10 min read
|
readTime: 10 min read
|
||||||
|
related_posts:
|
||||||
|
- k3s-cluster
|
||||||
|
- gitea-self-hosted-git
|
||||||
---
|
---
|
||||||
|
|
||||||
# GitOps with Flux CD
|
# GitOps with Flux CD
|
||||||
|
|
|
@ -63,7 +63,9 @@ const graphData = {
|
||||||
edges: []
|
edges: []
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create edges between posts and their tags
|
// Create edges between posts and their tags, and between related posts
|
||||||
|
const processedPostPairs = new Set(); // Keep track of processed pairs to avoid duplicate edges
|
||||||
|
|
||||||
sortedPosts
|
sortedPosts
|
||||||
.filter(post => !post.data.draft)
|
.filter(post => !post.data.draft)
|
||||||
.forEach(post => {
|
.forEach(post => {
|
||||||
|
@ -79,21 +81,58 @@ sortedPosts
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if post references other posts (optional)
|
// --- Combined Related Posts Logic ---
|
||||||
// This requires a related_posts field in frontmatter
|
let explicitRelatedSlugs = new Set(post.data.related_posts || []);
|
||||||
if (post.data.related_posts && Array.isArray(post.data.related_posts)) {
|
let relatedPostsForGraph = [];
|
||||||
post.data.related_posts.forEach(relatedSlug => {
|
|
||||||
// Make sure related post exists
|
// 1. Add explicitly related posts
|
||||||
if (sortedPosts.some(p => p.slug === relatedSlug)) {
|
explicitRelatedSlugs.forEach(relatedSlug => {
|
||||||
|
const relatedPost = sortedPosts.find(p => p.slug === relatedSlug && !p.data.draft);
|
||||||
|
if (relatedPost) {
|
||||||
|
relatedPostsForGraph.push(relatedPost);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Add implicitly related posts by tag similarity (if needed, up to a limit, e.g., 3 total)
|
||||||
|
const MAX_RELATED = 3; // Max related posts to show connections for
|
||||||
|
const MIN_SHARED_TAGS = 2; // Minimum shared tags for implicit relation
|
||||||
|
|
||||||
|
if (relatedPostsForGraph.length < MAX_RELATED && postTags.length > 0) {
|
||||||
|
sortedPosts
|
||||||
|
.filter(otherPost =>
|
||||||
|
!otherPost.data.draft &&
|
||||||
|
otherPost.slug !== post.slug && // Not the same post
|
||||||
|
!explicitRelatedSlugs.has(otherPost.slug) && // Not already explicitly related
|
||||||
|
!relatedPostsForGraph.some(rp => rp.slug === otherPost.slug) // Not already added
|
||||||
|
)
|
||||||
|
.forEach(otherPost => {
|
||||||
|
if (relatedPostsForGraph.length >= MAX_RELATED) return; // Stop if we have enough
|
||||||
|
|
||||||
|
const otherTags = otherPost.data.tags || [];
|
||||||
|
const sharedTags = postTags.filter(tag => otherTags.includes(tag));
|
||||||
|
|
||||||
|
if (sharedTags.length >= MIN_SHARED_TAGS) {
|
||||||
|
relatedPostsForGraph.push(otherPost);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Create edges for all found related posts (explicit + implicit)
|
||||||
|
relatedPostsForGraph.forEach(relatedPost => {
|
||||||
|
const pairKey1 = `${post.slug}-${relatedPost.slug}`;
|
||||||
|
const pairKey2 = `${relatedPost.slug}-${post.slug}`;
|
||||||
|
|
||||||
|
// Avoid duplicate edges (A->B and B->A)
|
||||||
|
if (!processedPostPairs.has(pairKey1) && !processedPostPairs.has(pairKey2)) {
|
||||||
graphData.edges.push({
|
graphData.edges.push({
|
||||||
source: post.slug,
|
source: post.slug,
|
||||||
target: relatedSlug,
|
target: relatedPost.slug,
|
||||||
type: 'post-post',
|
type: 'post-post', // Use consistent type
|
||||||
strength: 2
|
strength: explicitRelatedSlugs.has(relatedPost.slug) ? 3 : 1.5 // Stronger link if explicit
|
||||||
});
|
});
|
||||||
|
processedPostPairs.add(pairKey1); // Mark pair as processed
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Terminal commands for tech effect
|
// Terminal commands for tech effect
|
||||||
|
|
Loading…
Reference in New Issue