
Language 🇺🇸 English
Hexo Installation
Add Live Commenting to Hexo Sites
This guide adds the FastComments live commenting widget to the posts of a site built with Hexo.
Hexo does not include a comment system. Themes add comments through their own templates and configuration. The method in this guide uses Hexo's injector API from a script in the site's scripts folder, so it does not require editing theme files and works with any theme.
This tutorial requires a FastComments account. You can create an account here.
Step 1: Create a Script File 
Hexo loads every JavaScript file in the scripts folder of the site during initialization.
In the root folder of your Hexo site (the folder that contains _config.yml), create a folder named scripts if it does not exist. Inside it, create a file named fastcomments.js:

Use the scripts folder of the site, not a folder inside the theme, so that the file is kept when the theme is updated or replaced.
Step 2: Add the FastComments Code 
Copy the following code into scripts/fastcomments.js:

If you are logged in to FastComments, the snippet above contains your tenant ID. Otherwise, replace demo with your tenant ID.
The script behaves as follows:
hexo.extend.injector.registerinserts the HTML before the closing</body>tag of each generated page.- The third argument,
post, limits the injection to post pages, which are the pages where Hexo'sis_post()helper istrue. Home, archive, category, tag, and standalone pages do not receive the widget. A post that sets a differentlayoutin its front-matter is matched by that layout name instead ofpost. - The widget container is placed after the first
<article>element on the page. If the theme does not use an<article>element, the container is added at the end of the page body. urlIdis set to the path of the post, for example/2026/01/15/hello-world/. The comment thread for a post is identified by this path, so the same thread loads on the local preview server and on the deployed site. If you later change thepermalinkorrootsetting in_config.yml, the paths change and existing threads are no longer matched to their posts.
Injected values are generated once when Hexo starts, so the code reads the page path in the browser with window.location.pathname instead of using template variables such as page.path.
Step 3: Preview and Deploy 
Scripts are loaded when Hexo starts. If hexo server is already running, stop it and start it again so that it loads scripts/fastcomments.js:

Open a post at http://localhost:4000/ to check that the comment widget appears below the post content.
When the widget appears as expected, generate and deploy the site with your usual workflow, for example:

hexo clean removes the cache file and the previously generated files, so all posts are regenerated with the new script.
Disable Theme Comments 
Many Hexo themes include settings for third-party comment systems. If your theme already renders a comment section, disable it in the theme configuration so that posts do not show two comment sections.
The default theme, landscape, renders a comment section on posts when disqus_shortname is set, or when valine.enable is true and the Valine appId and appKey are set. To disable these, remove the disqus_shortname value and set valine.enable to false in the theme configuration (_config.landscape.yml in the site root, or the theme's own _config.yml).
For other themes, refer to the theme's documentation for the name of its comment settings.
Domain Errors 
The widget may show an authorization error like the following:
This error means the domain of the page is not in the list of domains allowed for your FastComments account.
Add the domain your Hexo site is deployed to on the domain configuration page of your account.
Customization 
Styling and configuration options for the widget are described in the Customization Documentation.
Configuration options are added to the object passed to window.FastCommentsUI in scripts/fastcomments.js. Restart hexo server after editing the file.