Repository: docsifyjs/docsify (2025-08-08T04:51:56Z)

Issue:
Use of Coverpage H1 (Title) as link to start of content not working as expected in v5 Preview
### Description

As mentioned in #2593 , the use of a Coverpage Title as a link to the main content of a Docsify site can be problematic due to the repeated use of the same id, however in v5 RC-1 this seemed to be supported (as expected).

### Expected behavior

When there is  H1 (title) in the Coverpage, this link when clicked should go to the first matching id in the main content area of Docsify, and not on the matching id within the Coverpage itself. The coverpage will always be displayed as the landing page for a Docsify site, so navigating to an id within the one screen long Coverpage is highly unlikely.

### Actual behavior

Currently, clicking on the H1 (title) of the Coverpage scrolls the Coverpage halfway up to where the H1 link is.

Docsify v5 preview codsandbox, click on coverpage title:
https://codesandbox.io/p/sandbox/docsify-v5-preview-coverpage-2d82hj

However, in Docsify v5 RC-1 this issue did not seem to be present, and works as expected:

Docsify v5 RC 1 codsandbox, click on coverpage title:
https://codesandbox.io/p/sandbox/docsify-v5-rc-1-coverpage-jx2rl3

The same logic seems to hold true when using a direct URL with the id which results in targeting the main content (which has the same id on the Coverpage):
https://paulhibbitts.github.io/docsify-v5-rc-1-coverpage/#/?id=docsify-template

### Steps to reproduce

1. Create Coverpage with H1 (title) such as "Quick start"
2. Create a main content Markdown file, with # Quick start as the content title
3. View the site, and click on the Coverpage H1 (title) link

Happy to help test/try possible approaches to this issue, thank you!

### Environment

Docsify v5 Preview

### Additional Information

- [x] Bug still occurs when all/other plugins are disabled?


Discussion:
This has nothing to do with v5; it was the same in v4. It has to do with anchors.

see https://github.com/docsifyjs/docsify/pull/2593#issuecomment-3162252970

There is a version number on the docsify site, so different IDs are generated. `# docsify <small>5.0.0-rc.1</small>` generates `id=docsify-500-rc1`




Introduced by #2569
Thank you very much @sy-records for looking into this issue! 🙏🏼 I see the PR and will test today and report back. I've just done a quick test and things look really good!



Patch:
diff --git a/docs/_coverpage.md b/docs/_coverpage.md
index e9292beaf..654bda622 100644
--- a/docs/_coverpage.md
+++ b/docs/_coverpage.md
@@ -2,7 +2,7 @@
 
 ![logo](_media/icon.svg)
 
-# docsify <small>5.0.0-rc.1</small>
+# docsify <small>5.0.0-rc.1</small> :id=docsify
 
 > A magical documentation site generator
 
diff --git a/src/core/event/index.js b/src/core/event/index.js
index f1a55715a..e14ecf365 100644
--- a/src/core/event/index.js
+++ b/src/core/event/index.js
@@ -416,9 +416,16 @@ export function Events(Base) {
 
       // Move focus to content area
       if (focusEl) {
-        focusEl.focus(settings);
+        if (!focusEl.hasAttribute('tabindex')) {
+          focusEl.setAttribute('tabindex', '-1');
+          focusEl.setAttribute('data-added-tabindex', 'true');
+        }
 
-        focusEl.scrollIntoView({ behavior: 'smooth', block: 'start' });
+        if (focusEl.hasAttribute('data-added-tabindex')) {
+          focusEl.scrollIntoView({ behavior: 'smooth' });
+        }
+
+        focusEl.focus(settings);
       }
 
       return focusEl;


Test patch:
diff --git a/test/integration/__snapshots__/docs.test.js.snap b/test/integration/__snapshots__/docs.test.js.snap
index ce0dc1978..26f170ded 100644
--- a/test/integration/__snapshots__/docs.test.js.snap
+++ b/test/integration/__snapshots__/docs.test.js.snap
@@ -5,7 +5,7 @@ exports[`Docs Site coverpage renders and is unchanged 1`] = `
       <div class="mask"></div>
       <div class="cover-main"><!-- markdownlint-disable first-line-h1 -->
 
-<p><img src="http://127.0.0.1:4000/_media/icon.svg" data-origin="_media/icon.svg" alt="logo"></p><h1 id="docsify-500-rc1" tabindex="-1"><a href="#/?id=docsify-500-rc1" data-id="docsify-500-rc1" class="anchor"><span>docsify <small>5.0.0-rc.1</small></span></a></h1><blockquote>
+<p><img src="http://127.0.0.1:4000/_media/icon.svg" data-origin="_media/icon.svg" alt="logo"></p><h1 id="docsify" tabindex="-1"><a href="#/?id=docsify" data-id="docsify" class="anchor"><span>docsify <small>5.0.0-rc.1</small></span></a></h1><blockquote>
 <p>A magical documentation site generator</p></blockquote>
 <ul><li>Simple and lightweight</li><li>No statically built HTML files</li><li>Multiple themes</li></ul><p><a href="#/?id=docsify" class="button primary">Get Started</a>
 <a href="https://github.com/docsifyjs/docsify/" target="_blank" rel="noopener" class="button secondary">GitHub</a></p><!-- ![color](#f0f0f0) -->