Skip to content

Commit b3c3610

Browse files
committed
fix: fix the number of lines displayed in the list information, and click on the list to jump to an exception; footnote link to jump to an exception
1 parent 1db3022 commit b3c3610

File tree

2 files changed

+80
-5
lines changed

2 files changed

+80
-5
lines changed

ui/src/components/QuestionList/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,21 @@ const QuestionList: FC<Props> = ({
173173
<h5 className="text-wrap text-break">
174174
<NavLink
175175
className="link-dark d-block"
176+
onClick={(e) => e.stopPropagation()}
176177
to={pathFactory.questionLanding(li.id, li.url_title)}>
177178
{li.title}
178179
{li.status === 2 ? ` [${t('closed')}]` : ''}
179180
</NavLink>
180181
</h5>
181182
{viewType === 'card' && (
182-
<NavLink
183-
to={pathFactory.questionLanding(li.id, li.url_title)}
184-
className="d-block mb-2 small text-body text-truncate-2"
185-
dangerouslySetInnerHTML={{ __html: li.description }}
186-
/>
183+
<div className="text-truncate-2 mb-2">
184+
<NavLink
185+
to={pathFactory.questionLanding(li.id, li.url_title)}
186+
className="d-block small text-body"
187+
dangerouslySetInnerHTML={{ __html: li.description }}
188+
onClick={(e) => e.stopPropagation()}
189+
/>
190+
</div>
187191
)}
188192

189193
<div className="question-tags mb-12">

ui/src/pages/Questions/Detail/index.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,77 @@ const Index = () => {
242242
}
243243
}
244244

245+
useEffect(() => {
246+
// handle footnote links
247+
const fixFootnoteLinks = () => {
248+
const footnoteLinks = document.querySelectorAll(
249+
'a[href^="#"]:not([data-footnote-fixed])',
250+
);
251+
252+
footnoteLinks.forEach((link) => {
253+
link.setAttribute('data-footnote-fixed', 'true');
254+
const href = link.getAttribute('href');
255+
link.addEventListener('click', (e) => {
256+
e.preventDefault();
257+
const targetId = href?.substring(1) || '';
258+
const targetElement = document.getElementById(targetId);
259+
260+
if (targetElement) {
261+
window.history.pushState(null, '', `${location.pathname}${href}`);
262+
263+
scrollToElementTop(targetElement);
264+
}
265+
});
266+
});
267+
268+
// 检查当前URL是否包含锚点,如果有,自动滚动到正确位置
269+
if (window.location.hash) {
270+
const { hash } = window.location;
271+
const targetElement = document.getElementById(hash.substring(1));
272+
273+
if (targetElement) {
274+
// 给浏览器一点时间来完成渲染
275+
setTimeout(() => {
276+
scrollToElementTop(targetElement);
277+
}, 100);
278+
}
279+
}
280+
};
281+
fixFootnoteLinks();
282+
283+
const observer = new MutationObserver(() => {
284+
fixFootnoteLinks();
285+
});
286+
287+
observer.observe(document.body, {
288+
childList: true,
289+
subtree: true,
290+
attributes: true,
291+
attributeFilter: ['id', 'href'],
292+
});
293+
294+
// 监听 URL hash 变化
295+
const handleHashChange = () => {
296+
if (window.location.hash) {
297+
const { hash } = window.location;
298+
const targetElement = document.getElementById(hash.substring(1));
299+
300+
if (targetElement) {
301+
setTimeout(() => {
302+
scrollToElementTop(targetElement);
303+
}, 100);
304+
}
305+
}
306+
};
307+
308+
window.addEventListener('hashchange', handleHashChange);
309+
310+
return () => {
311+
observer.disconnect();
312+
window.removeEventListener('hashchange', handleHashChange);
313+
};
314+
}, [location.pathname]);
315+
245316
return (
246317
<Row className="questionDetailPage pt-4 mb-5">
247318
<Col className="page-main flex-auto">

0 commit comments

Comments
 (0)