Compare commits
No commits in common. "ced630b71ad75a1ea9bb452fe019e79fc473a645" and "267396abe3aadef01f8f3f4e131cd67716c16d3a" have entirely different histories.
ced630b71a
...
267396abe3
|
@ -63,15 +63,13 @@ const graphData = {
|
||||||
edges: []
|
edges: []
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create edges between posts and their tags, and between related posts
|
// Create edges between posts and their tags
|
||||||
const processedPostPairs = new Set(); // Avoid duplicate A->B and B->A edges
|
|
||||||
|
|
||||||
sortedPosts
|
sortedPosts
|
||||||
.filter(post => !post.data.draft)
|
.filter(post => !post.data.draft)
|
||||||
.forEach(post => {
|
.forEach(post => {
|
||||||
const postTags = post.data.tags || [];
|
const postTags = post.data.tags || [];
|
||||||
|
|
||||||
// 1. Add edges from post to tags
|
// Add edges from post to tags
|
||||||
postTags.forEach(tag => {
|
postTags.forEach(tag => {
|
||||||
graphData.edges.push({
|
graphData.edges.push({
|
||||||
source: post.slug,
|
source: post.slug,
|
||||||
|
@ -80,60 +78,22 @@ sortedPosts
|
||||||
strength: 1
|
strength: 1
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Find Related Posts (Explicit + Implicit) ---
|
|
||||||
const MAX_RELATED_LINKS = 3;
|
|
||||||
const MIN_SHARED_TAGS_FOR_LINK = 2;
|
|
||||||
|
|
||||||
let relatedLinks = new Map(); // Use Map to store related slug and relation type (explicit/implicit)
|
// Check if post references other posts (optional)
|
||||||
|
// This requires a related_posts field in frontmatter
|
||||||
// a. Find explicitly related posts
|
if (post.data.related_posts && Array.isArray(post.data.related_posts)) {
|
||||||
const explicitSlugs = new Set(post.data.related_posts || []);
|
post.data.related_posts.forEach(relatedSlug => {
|
||||||
explicitSlugs.forEach(slug => {
|
// Make sure related post exists
|
||||||
if (sortedPosts.some(p => p.slug === slug && !p.data.draft)) {
|
if (sortedPosts.some(p => p.slug === relatedSlug)) {
|
||||||
relatedLinks.set(slug, 'explicit');
|
graphData.edges.push({
|
||||||
}
|
source: post.slug,
|
||||||
});
|
target: relatedSlug,
|
||||||
|
type: 'post-post',
|
||||||
// b. Find implicitly related posts by tag similarity (if needed)
|
strength: 2
|
||||||
if (relatedLinks.size < MAX_RELATED_LINKS && postTags.length > 0) {
|
});
|
||||||
const potentialRelated = sortedPosts
|
|
||||||
.filter(otherPost =>
|
|
||||||
!otherPost.data.draft &&
|
|
||||||
otherPost.slug !== post.slug && // Not the same post
|
|
||||||
!relatedLinks.has(otherPost.slug) // Not already added
|
|
||||||
)
|
|
||||||
.map(otherPost => {
|
|
||||||
const otherTags = otherPost.data.tags || [];
|
|
||||||
const sharedTagsCount = postTags.filter(tag => otherTags.includes(tag)).length;
|
|
||||||
return { slug: otherPost.slug, score: sharedTagsCount };
|
|
||||||
})
|
|
||||||
.filter(item => item.score >= MIN_SHARED_TAGS_FOR_LINK)
|
|
||||||
.sort((a, b) => b.score - a.score); // Sort by most shared tags
|
|
||||||
|
|
||||||
potentialRelated.forEach(item => {
|
|
||||||
if (relatedLinks.size < MAX_RELATED_LINKS) {
|
|
||||||
relatedLinks.set(item.slug, 'implicit');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Create edges for the found related posts
|
|
||||||
relatedLinks.forEach((relationType, relatedSlug) => {
|
|
||||||
const pairKey1 = `${post.slug}-${relatedSlug}`;
|
|
||||||
const pairKey2 = `${relatedSlug}-${post.slug}`;
|
|
||||||
|
|
||||||
if (!processedPostPairs.has(pairKey1) && !processedPostPairs.has(pairKey2)) {
|
|
||||||
graphData.edges.push({
|
|
||||||
source: post.slug,
|
|
||||||
target: relatedSlug,
|
|
||||||
type: 'post-post',
|
|
||||||
strength: relationType === 'explicit' ? 3 : 1.5 // Stronger edge for explicit links
|
|
||||||
});
|
|
||||||
processedPostPairs.add(pairKey1);
|
|
||||||
processedPostPairs.add(pairKey2); // Add both directions to set
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Terminal commands for tech effect
|
// Terminal commands for tech effect
|
||||||
|
|
Loading…
Reference in New Issue