Advanced Customization
ModernDuang provides a rich set of configuration options, but if you need deeper customization, you can extend the theme through the following methods.
Important: Always prefer using
_config.modernduang.ymlfor configurable adjustments. Avoid editing theme source files directly — this way your customizations won't be lost when updating the theme.
Overriding CSS Styles
ModernDuang uses CSS custom properties (variables) to control colors, spacing, shadows, and other visual properties. You can override these variables in source/css/main.css to customize the appearance.
Common CSS Variables
Here are the most important CSS variables in the theme:
Dark Mode Variables
How to Override
Edit source/css/main.css and add your custom styles at the end of the file:
Adding Custom JavaScript
You can add custom JavaScript code in source/js/main.js for additional interactive functionality.
Modifying Layout Templates
The theme's layout templates are located in the layout/ directory and use the EJS template engine. You can modify these files to adjust the HTML structure of your pages.
Main Template Files
Example: Add Custom Meta Tags in the Head
Edit layout/partials/header.ejs and add inside the <head> tag:
Example: Inject Analytics in the Footer
Edit layout/partials/footer.ejs and add before </body>:
Customizing the Link Apply Content
The "Exchange Links" section on the friend links page is powered by layout/_link-apply.md. This file uses standard Markdown syntax combined with special theme syntax to display your site information.
Template Structure
The section title is configured via YAML frontmatter at the top of the file. The body uses standard Markdown:
{%card%} Blocks
{%card%}content{%card%} wraps content in a clay-styled card container, used to highlight your site information. Note that the opening and closing tags use the same syntax.
<!-- siteinfo --> Placeholder
<!-- siteinfo --> is a special placeholder that is automatically replaced with your site information table:
Customizing the Apply Text
You can freely edit layout/_link-apply.md with any standard Markdown syntax. Just keep the <!-- siteinfo --> placeholder to display your site information — the rest is fully customizable.
Customizing the 404 Page
ModernDuang includes a built-in 404 page. To customize it, copy and modify the theme's 404 template:
Then edit layout/404.ejs and customize the content:
Adding Custom Fonts
Method 1: Add Google Fonts via Config
Configure the font option in _config.modernduang.yml:
Tip for users in China: If Google Fonts loads slowly, change
font.hostto a mirror, such ashttps://fonts.googleapis.cnorhttps://fonts.loli.net.
Method 2: Load Local Fonts via CSS
Edit source/css/main.css and use @font-face to load local fonts:
Place font files in your Hexo site's source/fonts/ directory.
Adding Custom Scripts
Analytics Scripts
For simple third-party scripts, use the footer.custom field with a single-line string:
For complex multi-line scripts (e.g., Google Analytics, Baidu Tongji), it's recommended to inject them via the EJS template instead — see the example in the Layout Templates section above.
If you need to inject scripts in the <head> (rather than the footer), edit layout/partials/header.ejs and add your script tags inside the <head> element.
Understanding Theme Scripts
ModernDuang includes several Hexo helper scripts in the scripts/ directory that extend Hexo's build capabilities. You can create your own scripts in your Hexo site's scripts/ directory to add new functionality.
Built-in Scripts
How mermaid.js Works
This script detects the mermaid: true flag in page frontmatter during Hexo build. When detected, it injects the Mermaid CDN script and initialization code at the bottom of the page:
How note-tags.js Works
This script registers a series of Hexo tag plugins for creating specially styled blockquotes in Markdown:
The script registers paired tags (note, warning, declare, danger) that wrap their content in styled HTML containers with icons, colors, and mouse-tracking glow effects.
