-
Notifications
You must be signed in to change notification settings - Fork 273
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
feat: sync 3.20.0 to dev #2639
feat: sync 3.20.0 to dev #2639
Changes from all commits
5669126
455668d
e81f11c
678ab67
490ad10
1908d57
faa99de
c6a0664
ff0247d
43333e4
569ac3c
c79dd29
baaa366
ba839e0
df63204
c9991b2
36b3838
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||||||||||
const OPEN_TINY_URL = 'https://opentiny.design' | ||||||||||||||
|
||||||||||||||
export const doSearchEverySite = () => { | ||||||||||||||
window.handleGlobalSearchData = (resolve) => { | ||||||||||||||
return (data) => { | ||||||||||||||
if (typeof data.content === 'string') { | ||||||||||||||
data.content = data.content.replaceAll(OPEN_TINY_URL, window.location.origin) | ||||||||||||||
} | ||||||||||||||
Comment on lines
+6
to
+8
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. Ensure compatibility of The Apply this diff to enhance compatibility: - data.content = data.content.replaceAll(OPEN_TINY_URL, window.location.origin)
+ data.content = data.content.replace(new RegExp(OPEN_TINY_URL, 'g'), window.location.origin) 📝 Committable suggestion
Suggested change
|
||||||||||||||
|
||||||||||||||
resolve(data) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default function viteDosearchPlugin() { | ||
return { | ||
name: 'vite-dosearch-plugin', | ||
enforce: 'pre', | ||
transform(code, id) { | ||
if (id.includes('@docsearch')) { | ||
const newCode = code.replace( | ||
'Promise((function(t){var n=new XMLHttpRequest;', | ||
'Promise((function(t){t=window.handleGlobalSearchData(t);var n=new XMLHttpRequest;' | ||
) | ||
return { | ||
code: newCode, | ||
map: null | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,6 +12,9 @@ | |||||||||||||||||||||||||||
import type { IAnchorRenderlessParams, IAnchorLinkItem } from '@/types' | ||||||||||||||||||||||||||||
import { addClass, removeClass } from '../common/deps/dom' | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const getEleMentBySelect = (parent, selector) => | ||||||||||||||||||||||||||||
selector?.startsWith('#') ? document.getElementById(selector.slice(1)) : parent.querySelector(selector) | ||||||||||||||||||||||||||||
Comment on lines
+15
to
+16
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. 🛠️ Refactor suggestion Improve naming convention and add input validation The function name -const getEleMentBySelect = (parent, selector) =>
+const getElementById = (id) => document.getElementById(id)
+const querySelector = (parent, selector) => parent?.querySelector(selector)
+
+const getElementBySelector = (parent, selector) => {
+ if (!selector || typeof selector !== 'string') {
+ return null
+ }
+ return selector.startsWith('#')
+ ? getElementById(selector.slice(1))
+ : querySelector(parent, selector)
+} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export const setFixAnchor = | ||||||||||||||||||||||||||||
({ vm, props }: Pick<IAnchorRenderlessParams, 'vm' | 'props'>) => | ||||||||||||||||||||||||||||
() => { | ||||||||||||||||||||||||||||
|
@@ -25,7 +28,7 @@ export const setFixAnchor = | |||||||||||||||||||||||||||
const setMarkClass = ({ state, props }: Pick<IAnchorRenderlessParams, 'state' | 'props'>) => { | ||||||||||||||||||||||||||||
const { scrollContainer } = state | ||||||||||||||||||||||||||||
const { markClass } = props | ||||||||||||||||||||||||||||
const activeContentEl = scrollContainer.querySelector(`${state.currentLink}`) | ||||||||||||||||||||||||||||
const activeContentEl = getEleMentBySelect(scrollContainer, `${state.currentLink}`) | ||||||||||||||||||||||||||||
if (markClass) { | ||||||||||||||||||||||||||||
addClass(activeContentEl, markClass) | ||||||||||||||||||||||||||||
setTimeout(() => { | ||||||||||||||||||||||||||||
|
@@ -95,7 +98,7 @@ const addObserver = ({ props, state }: Pick<IAnchorRenderlessParams, 'props' | ' | |||||||||||||||||||||||||||
list.forEach((item) => { | ||||||||||||||||||||||||||||
const link = item.link | ||||||||||||||||||||||||||||
expandLink[link] = item | ||||||||||||||||||||||||||||
const linkEl = document.querySelector(link) | ||||||||||||||||||||||||||||
const linkEl = getEleMentBySelect(document, link) | ||||||||||||||||||||||||||||
linkEl && intersectionObserver.observe(linkEl) | ||||||||||||||||||||||||||||
if (item.children) { | ||||||||||||||||||||||||||||
observer(item.children) | ||||||||||||||||||||||||||||
|
@@ -127,13 +130,13 @@ const setChildOffsetTop = ({ state, props }: Pick<IAnchorRenderlessParams, 'stat | |||||||||||||||||||||||||||
if (!props.links?.length) { | ||||||||||||||||||||||||||||
return | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
state.childOffsetTop = document.querySelector(props.links[0].link)?.offsetTop || 0 | ||||||||||||||||||||||||||||
state.childOffsetTop = getEleMentBySelect(document, props.links[0].link)?.offsetTop || 0 | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export const getContainer = | ||||||||||||||||||||||||||||
({ props }: Pick<IAnchorRenderlessParams, 'props'>) => | ||||||||||||||||||||||||||||
(): Element => | ||||||||||||||||||||||||||||
(props.containerId && document.querySelector(props.containerId)) || document.body | ||||||||||||||||||||||||||||
(props.containerId && getEleMentBySelect(document, props.containerId)) || document.body | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export const mounted = | ||||||||||||||||||||||||||||
({ state, api, props, nextTick }: Pick<IAnchorRenderlessParams, 'state' | 'api' | 'props' | 'nextTick'>) => | ||||||||||||||||||||||||||||
|
@@ -234,7 +237,7 @@ export const linkClick = | |||||||||||||||||||||||||||
setMarkClass({ state, props }) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if (scrollContainer && scrollContainer !== document.body && !isChangeHash) { | ||||||||||||||||||||||||||||
const linkEl = scrollContainer.querySelector(item.link) as HTMLElement | ||||||||||||||||||||||||||||
const linkEl = getEleMentBySelect(scrollContainer, item.link) as HTMLElement | ||||||||||||||||||||||||||||
const top = | ||||||||||||||||||||||||||||
linkEl?.getBoundingClientRect().top - | ||||||||||||||||||||||||||||
scrollContainer.getBoundingClientRect().top + | ||||||||||||||||||||||||||||
|
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.
Critical: Move DocSearch API credentials to environment variables
The DocSearch API credentials are hardcoded in the source code, which poses a security risk. These should be moved to environment variables.
Apply this change:
📝 Committable suggestion
🧰 Tools
🪛 Gitleaks (8.21.2)
46-46: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)