Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core/event/index.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
import { isMobile, mobileBreakpoint } from '../util/env.js';
import * as dom from '../util/dom.js';
import { stripUrlExceptId } from '../router/util.js';

/** @typedef {import('../Docsify.js').Constructor} Constructor */

Expand DownExpand Up@@ -474,6 +475,8 @@ export function Events(Base) {
return;
}

href = stripUrlExceptId(href);

const oldActive = dom.find(sidebar, 'li.active');
const newActive = dom
.find(
Expand Down
3 changes: 2 additions & 1 deletion src/core/render/compiler/heading.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import {
getAndRemoveDocsifyIgnoreConfig,
} from '../utils.js';
import { slugify } from '../slugify.js';
import { stripUrlExceptId } from '../../router/util.js';

export const headingCompiler = ({ renderer, router, compiler }) =>
(renderer.heading = function ({ tokens, depth }) {
Expand All@@ -20,7 +21,7 @@ export const headingCompiler = ({ renderer, router, compiler }) =>
nextToc.ignoreSubHeading = ignoreSubHeading;
const slug = slugify(config.id || str);
const url = router.toURL(router.getCurrentPath(), { id: slug });
nextToc.slug = url;
nextToc.slug = stripUrlExceptId(url);
compiler.toc.push(nextToc);

// Note: tabindex="-1" allows programmatically focusing on heading
Expand Down
16 changes: 16 additions & 0 deletions src/core/router/util.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,6 +40,22 @@ export function stringifyQuery(obj, ignores = []) {
return qs.length ? `?${qs.join('&')}` : '';
}

export function stripUrlExceptId(str) {
const [path, queryString] = str.split('?');
Comment thread
Koooooo-7 marked this conversation as resolved.
if (!queryString) {
return str;
}

const params = new URLSearchParams(queryString);
const id = params.get('id');

if (id !== null) {
return `${path}?id=${id}`;
}

return path;
}

export const isAbsolutePath = cached(path => {
return /(:|(\/{2}))/g.test(path);
});
Expand Down
16 changes: 8 additions & 8 deletions src/plugins/search/component.js
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { search } from './search.js';
import { escapeHtml, search } from './search.js';
import cssText from './style.css';

let NO_DATA_TEXT = '';
Expand DownExpand Up@@ -75,11 +75,11 @@ function bindEvents() {
let timeId;

/**
Prevent to Fold sidebar.

When searching on the mobile end,
the sidebar is collapsed when you click the INPUT box,
making it impossible to search.
* Prevent to Fold sidebar.
*
* When searching on the mobile end,
* the sidebar is collapsed when you click the INPUT box,
* making it impossible to search.
*/
Docsify.dom.on(
$search,
Expand DownExpand Up@@ -129,10 +129,10 @@ export function init(opts, vm) {
return;
}

const keywords = vm.router.parse().query.s;
const keywords = vm.router.parse().query.s || '';

Docsify.dom.style(cssText);
tpl(vm, keywords);
tpl(vm, escapeHtml(keywords));
bindEvents();
keywords && setTimeout(_ => doSearch(keywords), 500);
}
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/search/search.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ import {
import { markdownToTxt } from './markdown-to-txt.js';
import Dexie from 'dexie';

let INDEXES = {};
let INDEXES = [];

const db = new Dexie('docsify');
db.version(1).stores({
Expand DownExpand Up@@ -48,7 +48,7 @@ function resolveIndexKey(namespace) {
: LOCAL_STORAGE.INDEX_KEY;
}

function escapeHtml(string) {
export function escapeHtml(string) {
const entityMap = {
'&': '&',
'<': '&lt;',
Expand DownExpand Up@@ -102,7 +102,7 @@ function getListData(token) {
export function genIndex(path, content = '', router, depth, indexKey) {
const tokens = window.marked.lexer(content);
const slugify = window.Docsify.slugify;
const index = {};
const index = [];
let slug;
let title = '';

Expand DownExpand Up@@ -299,7 +299,7 @@ export async function init(config, vm) {
INDEXES = await getData(indexKey);

if (isExpired) {
INDEXES = {};
INDEXES = [];
} else if (!isAuto) {
return;
}
Expand Down
Loading