Head Integrations & Meta Tags
Relevant source files
The following files were used as context for generating this wiki page:
The "Head Integrations & Meta Tags" system in the WHK project manages the technical metadata, SEO attributes, and resource preloading required for a high-performance educational blog. This system ensures that every page contains accurate semantic information, optimized resource loading for mathematics (KaTeX) and typography, and clean, deduplicated HTML output during the build process.
The system relies on a combination of static template overrides, automated script-based frontmatter generation using AI, and a specialized build pipeline that post-processes the <head> section of HTML files to optimize delivery and minimize redundant tags.
Meta Tag Generation & SEO Strategy
The project employs an automated approach to SEO through frontmatter generation. This process uses AI to analyze document content and headings to produce structured metadata that is eventually rendered into the HTML <head>.
Frontmatter Schema
Every Markdown document in the science directory is processed to include specific SEO-optimized fields. The generate_frontmatter.js script targets these dimensions to ensure the knowledge base is discoverable.
| Field | Description | Constraints / Requirements |
|---|---|---|
title | SEO Creative Title | 20-25 Chinese characters; Format: "[Core Term] Analysis: [Mechanism] & [Scenario]" |
description | Technical description | 100-200 Chinese characters; must reveal technical route or mechanism |
summary | Card summary | 50-100 Chinese characters for UI preview cards |
tags | Atomic tags | 15-25 tags covering Discipline, Core Term, Detail Term, Application, and Target Audience |
Sources: scripts/frontmatter/generate_frontmatter.js:132-150, scripts/frontmatter/generate_frontmatter.js:175-182
Automated Meta Flow
The following diagram illustrates how raw document content is transformed into SEO metadata:
The workflow utilizes the nvidia/nemotron-3-nano-30b-a3b model to ensure "Expert Mode" metadata quality.
Sources: scripts/frontmatter/generate_frontmatter.js:125-130, scripts/frontmatter/generate_frontmatter.js:185-200
Template Integrations
The project uses MkDocs Material overrides to inject specific links, scripts, and styles into the <head> section. This is primarily handled in head.html.
Resource Preloading & Connectivity
To optimize the rendering of mathematical content and specialized typography, the project pre-connects to CDNs and preloads critical font files.
- CDN Preconnect: Establishes early connections to
cdn.jsdelivr.net. - Font Preloading: Preloads several
woff2font weights from the@raineblog/mkdocs-fontkitpackage to prevent layout shifts. - Language Tags: Forces
zh-CNcontent language and defines canonical alternates forzh-Hansandzh-CN.
Sources: overrides/partials/integrations/head.html:1-15
Style Overrides
The <head> section includes a <style> block that defines the global design tokens and layout fixes:
- Typography: Custom CSS variables
--fontkit-text-fontand--fontkit-code-fontdefine the font stacks for text and code. - Layout: Centers headings (
h2,h3) and images within the.md-typesetcontainer. - Print Optimization: Includes an
@media printblock to hide non-printable elements and ensure links are underlined.
Sources: overrides/partials/integrations/head.html:18-85
Build-Time Head Optimization
The build.ts script performs "in-place optimization" on the generated HTML files. A significant portion of this logic is dedicated to cleaning and reordering the <head> content.
Deduplication and Cleaning
The build pipeline includes several custom PostHTML plugins specifically designed for the <head> section:
deduplicateMeta: Removes redundantdescription,author, andkeywordstags, keeping only the last occurrence.deduplicateLinks: Removes duplicate canonical and alternate links.deduplicateStructuredData: Removes duplicateapplication/ld+jsonblocks based on@typeand@id.removeEmptyElements: Purges empty<style>or<script>tags that contain no content orsrc.
Sources: build.ts:114-165, build.ts:200-230, build.ts:316-340
Head Element Reordering
To follow performance best practices, the system reorders elements within the <head> using the reorderHead plugin.
Sources: build.ts:232-280
Mathematics & KaTeX Integration
Integration of mathematical formulas is handled via the katex-ssr plugin and the head.html template.
Configuration
The project uses a custom KaTeX SSR plugin (disabled in serve mode for performance) that injects necessary JavaScript and CSS.
- CSS: Loaded via
katex.min.cssin the head. - Macros: Extensive math macros (e.g.,
\RR,\ce,\poly,\pH) are defined in the configuration to ensure consistent rendering across the site. - Layout Fixes: The
head.htmltemplate includes specific CSS to preventarithmatexcontainers from overflowing and to adjust margins forkatex-displayelements.
Sources: scripts/template.serve.yml:32-75, overrides/partials/integrations/head.html:45-55, overrides/partials/integrations/head.html:95
Summary
The "Head Integrations & Meta Tags" system is a multi-layered architecture designed for SEO excellence and rapid page loads. By combining AI-driven frontmatter generation, aggressive build-time deduplication, and strategic resource preloading, the WHK project maintains a technically superior document structure that supports complex scientific notation and high-quality Chinese typography. This ensures that the learning notes are not only human-readable but also highly optimized for search engines and modern web browsers.