refactor: remove unused metadata extraction (tags/wordCount)

- Remove extractTags() and calculateWordCount() methods (dead code)
- Keep only extractTitle() method in MetadataExtractor
- Remove includeMetadata option and related infrastructure
- Update PreprocessingResult interfaces across all processors
- Remove wordCount from metadata schema
- Tags still populated from frontmatter (FrontmatterProcessor)
- Build verification passes without errors

Analysis showed these methods extracted data never consumed by Typst
templates or PDF generation pipeline.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jarvis committed 2025-09-09 22:39:38 +02:00
1 parent a6b35d336a
commit 09365e2d75
5 files changed
+4 -87

No files matched your search

+2 -21
View File
@@ -10,8 +10,6 @@ import { CalloutProcessor } from './preprocessors/CalloutProcessor';
import { MetadataExtractor } from './preprocessors/MetadataExtractor'; import { MetadataExtractor } from './preprocessors/MetadataExtractor';
export interface PreprocessorOptions { export interface PreprocessorOptions {
/** Include metadata extraction in processing */
includeMetadata: boolean;
/** Preserve existing frontmatter */ /** Preserve existing frontmatter */
preserveFrontmatter: boolean; preserveFrontmatter: boolean;
/** Base URL for relative link resolution */ /** Base URL for relative link resolution */
@@ -29,7 +27,6 @@ export interface PreprocessingResult {
tags: string[]; tags: string[];
frontmatter?: Record<string, any>; frontmatter?: Record<string, any>;
title?: string; title?: string;
wordCount: number;
pdfEmbeds?: Array<{ pdfEmbeds?: Array<{
originalPath: string; originalPath: string;
sanitizedPath: string; sanitizedPath: string;
@@ -123,8 +120,7 @@ export class MarkdownPreprocessor {
metadata: { metadata: {
tags: [], tags: [],
frontmatter: undefined, frontmatter: undefined,
title: undefined, title: undefined
wordCount: 0
}, },
errors: [], errors: [],
warnings: [] warnings: []
@@ -134,17 +130,6 @@ export class MarkdownPreprocessor {
// Step 1: Extract and process frontmatter first (always process for metadata extraction) // Step 1: Extract and process frontmatter first (always process for metadata extraction)
result.content = this.frontmatterProcessor.processFrontmatter(result.content, result); result.content = this.frontmatterProcessor.processFrontmatter(result.content, result);
// Step 2: Extract additional tags from content (combine with frontmatter tags)
if (this.options.includeMetadata) {
const contentTags = MetadataExtractor.extractTags(result.content);
// Merge content tags with frontmatter tags, avoiding duplicates
for (const tag of contentTags) {
if (!result.metadata.tags.includes(tag)) {
result.metadata.tags.push(tag);
}
}
}
// Step 3: Convert email blocks to Typst format // Step 3: Convert email blocks to Typst format
result.content = this.calloutProcessor.processEmailBlocks(result.content, result); result.content = this.calloutProcessor.processEmailBlocks(result.content, result);
@@ -161,10 +146,7 @@ export class MarkdownPreprocessor {
// Step 7: Convert callouts // Step 7: Convert callouts
result.content = this.calloutProcessor.processCallouts(result.content, result); result.content = this.calloutProcessor.processCallouts(result.content, result);
// Step 8: Calculate final metadata // Extract title from content if not available from frontmatter
result.metadata.wordCount = MetadataExtractor.calculateWordCount(result.content);
// Use title from frontmatter if available, otherwise extract from content
if (!result.metadata.title) { if (!result.metadata.title) {
result.metadata.title = MetadataExtractor.extractTitle(result.content); result.metadata.title = MetadataExtractor.extractTitle(result.content);
} }
@@ -221,7 +203,6 @@ export class MarkdownPreprocessor {
// Default configurations // Default configurations
export const DEFAULT_PREPROCESSOR_OPTIONS: PreprocessorOptions = { export const DEFAULT_PREPROCESSOR_OPTIONS: PreprocessorOptions = {
includeMetadata: true,
preserveFrontmatter: true, preserveFrontmatter: true,
baseUrl: '' baseUrl: ''
}; };
@@ -19,7 +19,6 @@ export interface PreprocessingResult {
tags: string[]; tags: string[];
frontmatter?: Record<string, any>; frontmatter?: Record<string, any>;
title?: string; title?: string;
wordCount: number;
pdfEmbeds?: Array<{ pdfEmbeds?: Array<{
originalPath: string; originalPath: string;
sanitizedPath: string; sanitizedPath: string;
@@ -1,72 +1,11 @@
/** /**
* MetadataExtractor.ts * MetadataExtractor.ts
* *
* Handles extraction of metadata from markdown content including tags, titles, and word counts. * Handles extraction of metadata from markdown content for PDF export.
* This module provides pure utility functions for processing markdown content to extract * Currently focuses on title extraction from markdown headings.
* various metadata elements used in the PDF export process.
*/ */
export class MetadataExtractor { export class MetadataExtractor {
/**
* Extracts hashtags from markdown content while avoiding false positives
* from code blocks and markdown headings.
*
* @param content - The markdown content to extract tags from
* @returns Array of unique tags found in the content (without # prefix)
*/
public static extractTags(content: string): string[] {
const tags: string[] = [];
// Use more sophisticated regex to avoid false positives
// This pattern matches hashtags that are:
// 1. At the start of a line (with optional whitespace)
// 2. After whitespace
// 3. Not part of headings (# ## ### etc.)
// 4. Not inside code blocks or inline code
const enhancedTagPattern = /(?:^|\s)#([a-zA-Z][a-zA-Z0-9_/-]*[a-zA-Z0-9_]|[a-zA-Z][a-zA-Z0-9_]*)/gm;
// Remove code blocks to avoid extracting tags from them
const contentWithoutCodeBlocks = content
.replace(/```[\s\S]*?```/g, '') // Remove fenced code blocks
.replace(/`[^`\n]*`/g, ''); // Remove inline code
let match;
while ((match = enhancedTagPattern.exec(contentWithoutCodeBlocks)) !== null) {
const tag = match[1]; // Get the tag without the # prefix
// Additional validation to ensure it's a proper tag
if (tag && tag.length > 0 && !tags.includes(tag)) {
// Skip if it looks like a heading (check if preceded by multiple #)
const fullMatch = match[0];
const beforeTag = contentWithoutCodeBlocks.substring(Math.max(0, match.index - 5), match.index);
// Skip if this appears to be part of a markdown heading
if (!beforeTag.includes('#')) {
tags.push(tag);
}
}
}
enhancedTagPattern.lastIndex = 0; // Reset regex state
return tags;
}
/**
* Calculates word count for markdown content by removing formatting and counting words.
*
* @param content - The markdown content to count words in
* @returns Number of words in the content
*/
public static calculateWordCount(content: string): number {
// Remove markdown syntax and count words
const plainText = content
.replace(/[#*_`~\[\]()]/g, '') // Remove markdown formatting
.replace(/\s+/g, ' ') // Normalize whitespace
.trim();
return plainText ? plainText.split(/\s+/).length : 0;
}
/** /**
* Extracts title from markdown content by looking for the first heading. * Extracts title from markdown content by looking for the first heading.
* *
@@ -25,7 +25,6 @@ export interface PreprocessingResult {
tags: string[]; tags: string[];
frontmatter?: Record<string, any>; frontmatter?: Record<string, any>;
title?: string; title?: string;
wordCount: number;
pdfEmbeds?: Array<{ pdfEmbeds?: Array<{
originalPath: string; originalPath: string;
sanitizedPath: string; sanitizedPath: string;
-1
View File
@@ -159,7 +159,6 @@ export class ExportOrchestrator {
const preprocessor = new MarkdownPreprocessor({ const preprocessor = new MarkdownPreprocessor({
vaultPath: vaultPath, vaultPath: vaultPath,
options: { options: {
includeMetadata: true,
preserveFrontmatter: config.printFrontmatter ?? this.plugin.settings.behavior.printFrontmatter, preserveFrontmatter: config.printFrontmatter ?? this.plugin.settings.behavior.printFrontmatter,
baseUrl: undefined, baseUrl: undefined,
printFrontmatter: config.printFrontmatter ?? this.plugin.settings.behavior.printFrontmatter printFrontmatter: config.printFrontmatter ?? this.plugin.settings.behavior.printFrontmatter