computeFrontmatterHashFromContent is the shared core that computes the hash given the already-read file content and pre-parsed frontmatter map (may be nil).
(content string, parsedFrontmatter map[string]any, filePath string, cache *ImportCache, fileReader FileReader)
| 180 | // computeFrontmatterHashFromContent is the shared core that computes the hash given the |
| 181 | // already-read file content and pre-parsed frontmatter map (may be nil). |
| 182 | func computeFrontmatterHashFromContent(content string, parsedFrontmatter map[string]any, filePath string, cache *ImportCache, fileReader FileReader) (string, error) { |
| 183 | frontmatterHashLog.Printf("Computing hash from content: filePath=%s, content_size=%d bytes", filePath, len(content)) |
| 184 | |
| 185 | // Extract frontmatter and markdown as text (no YAML parsing) |
| 186 | frontmatterText, markdown, err := extractFrontmatterAndBodyText(content) |
| 187 | if err != nil { |
| 188 | return "", fmt.Errorf("failed to extract frontmatter: %w", err) |
| 189 | } |
| 190 | |
| 191 | // Get base directory for resolving imports |
| 192 | baseDir := filepath.Dir(filePath) |
| 193 | |
| 194 | // Detect inlined-imports from the pre-parsed frontmatter map. |
| 195 | // If nil (parsing failed or not provided), inlined-imports is treated as false. |
| 196 | inlinedImports := parseBoolFromFrontmatter(parsedFrontmatter, "inlined-imports") |
| 197 | frontmatterHashLog.Printf("Hash strategy: inlined_imports=%v, markdown_size=%d bytes", inlinedImports, len(markdown)) |
| 198 | |
| 199 | // When inlined-imports is enabled, the entire markdown body is compiled into the lock |
| 200 | // file, so any change to the body must invalidate the hash. Include the full body text. |
| 201 | // Otherwise, only extract the relevant template expressions (env./vars. references). |
| 202 | var relevantExpressions []string |
| 203 | var fullBody string |
| 204 | if inlinedImports { |
| 205 | fullBody = normalizeFrontmatterText(markdown) |
| 206 | } else { |
| 207 | relevantExpressions = extractRelevantTemplateExpressions(markdown) |
| 208 | } |
| 209 | |
| 210 | // Compute hash using text-based approach with custom file reader |
| 211 | return computeFrontmatterHashTextBasedWithReader(frontmatterText, fullBody, baseDir, cache, relevantExpressions, fileReader) |
| 212 | } |
| 213 | |
| 214 | // extractRelevantTemplateExpressions extracts template expressions from markdown |
| 215 | // that reference env. or vars. contexts |
no test coverage detected