-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: genIndex error for search #1933
Changes from 5 commits
306d606
30fa174
86d3c5f
7b974ef
fa12461
558a8d1
70e921b
95bfa6d
b1df79d
f41ee5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,20 @@ export function genIndex(path, content = '', router, depth) { | |
slug = router.toURL(path, { id: slugify(escapeHtml(text)) }); | ||
} | ||
|
||
// fix 404 | ||
let pathname = location.pathname; | ||
let flag = false; | ||
while (slug.startsWith('#/../') && pathname.lastIndexOf('/') > 1) { | ||
flag = true; | ||
if (pathname.endsWith('/')) { | ||
pathname = pathname.substring(0, pathname.length - 1); | ||
} | ||
pathname = pathname.substring(0, pathname.lastIndexOf('/')); | ||
|
||
slug = '#/' + slug.substring(5); | ||
} | ||
slug = pathname + (flag ? '/' : '') + slug; | ||
|
||
if (str) { | ||
title = removeDocsifyIgnoreTag(str); | ||
} | ||
|
@@ -128,9 +142,7 @@ export function genIndex(path, content = '', router, depth) { | |
token.text = getTableData(token); | ||
token.text = getListData(token); | ||
|
||
index[slug].body = index[slug].body | ||
? index[slug].body + token.text | ||
: token.text; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
120 if (!index[slug]) {
121 index[slug] = { slug, title: '', body: '' };
122 } else if (index[slug].body) {
......
127 } else {
...... //index[slug].body is always undefined
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice point. |
||
index[slug].body = token.text || ''; | ||
} | ||
} | ||
}); | ||
|
@@ -277,9 +289,9 @@ export function init(config, vm) { | |
|
||
const isExpired = localStorage.getItem(expireKey) < Date.now(); | ||
|
||
INDEXS = JSON.parse(localStorage.getItem(indexKey)); | ||
INDEXS = isExpired ? null : JSON.parse(localStorage.getItem(indexKey)); | ||
|
||
if (isExpired) { | ||
if (!INDEXS) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When manually delete There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user should know what he does when he gonna manually delete index. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to reduce a manual operation step during the test, haha. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If user wanna break it, he should break it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then this change is not necessary, is it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yep. personally, I think we do not need handle this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
INDEXS = {}; | ||
} else if (!isAuto) { | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does those changes for ? could you plz give a sample and add verify test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When my website has multiple paths, it can prevent 404 error.
For example:
http://xxxxxx/A/
http://xxxxxx/B/
When searching on page A and accessing page B, 404 will appear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, maybe u can take a look on this
namespace
configs here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I configure it like this?
or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you need distinguish those namespace for different paths (sites), may could refer to our site with multi langs nav . if you deploy multi sites in same domain, the
namespace
config should be in each site'sindex.html search config
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will try it.