v.1 : 게시판이 붙을 경우 검색 안됨
document.querySelectorAll(".content").forEach(content => {
content.innerHTML = content.innerHTML.replace(/#([\w가-힣_]+)/g, function (match, tag) {
return `<a href="?search=${tag}">${match}</a>`;
});
});
#hashtag
v.2 : 글 본문에서 검색 안됨
document.querySelectorAll(".content").forEach(content => { // 현재 페이지 URL에서 마지막 경로(게시판 ID) 가져오기 const pathParts = window.location.pathname.split("/").filter(Boolean); // 빈 값 제거 const boardId = pathParts.length > 0 ? pathParts[pathParts.length - 1] : ""; // 마지막 경로 값 (게시판 ID) console.log(boardId); // 변수명 수정 content.innerHTML = content.innerHTML.replace(/#([\w가-힣_]+)/g, function (match, tag) { if (boardId) { return `<a href="./${boardId}/?search_keyword=${tag}&search_target=title_content">${match}</a>`; } else { return `<a href="./?search_keyword=${tag}&search_target=title_content">${match}</a>`; } }); });
v.3
document.querySelectorAll(".content").forEach(content => { // 현재 페이지 URL에서 경로 가져오기 const pathParts = window.location.pathname.split("/").filter(Boolean); // 빈 값 제거 let boardId = pathParts.length > 0 ? pathParts[0] : ""; // 첫 번째 경로(게시판 ID) // 글 번호(두 번째 경로)가 있으면 제거 (ex: threads/471363 → threads/) if (pathParts.length > 1 && !isNaN(pathParts[1])) { boardId = pathParts[0]; // 첫 번째 경로만 남기기 } console.log("게시판 ID:", boardId); // 디버깅용 content.innerHTML = content.innerHTML.replace(/#([\w가-힣_]+)/g, function (match, tag) { if (boardId) { return `<a href="/${boardId}/?search_keyword=${tag}&search_target=title_content">${match}</a>`; } else { return `<a href="/?search_keyword=${tag}&search_target=title_content">${match}</a>`; } }); });
참조
https://codepen.io/nikolett_codes/pen/daWxea
https://xe1.xpressengine.com/?mid=download&package_id=22753681
https://xe1.xpressengine.com/index.php?mid=download&package_id=22753695
제목 | 날짜 | ||
---|---|---|---|
23 | 라이믹스 후하니 스티커 모듈 | 2025/01/21 | 1 |
해시태그 자바스크립트 | 2025/02/01 | 2 | |
21 | [미입금] 새로운 사이트에 후하니님의 스티커 모듈 설치 의뢰 [1] | 2025/01/21 | 2 |
20 | 스크랩(threads) v1 [1] | 2025/01/31 | 2 |
19 | 글보기에서 바로 비밀글 설정하는 방법 [1] | 2025/01/30 | 3 |
18 | 더보기 php 코드 | 2025/01/31 | 3 |
17 | 스크랩 ec_imin | 2025/01/31 | 3 |
16 | 레이아웃을 바꿔봤습니다. | 2025/01/29 | 4 |
15 | [XE] 인기검색어 모듈+애드온+위젯 패키지 (PHP8수정버전) 문의 드립니다 [1] | 2025/01/06 | 5 |
14 | [Tips] 라이믹스 모든 글 최신글 가져오기 코드 | 2025/01/29 | 6 |
13 | 라이믹스 debugPrint | 2025/01/24 | 8 |
12 | [Tips] 라이믹스 특정 게시판 글 가져오기 | 2025/01/29 | 9 |
11 | 엘리스디지털배움폰트 | 2025/01/29 | 9 |
10 | [레거시코드] pointhistory 모듈 유지보수 방법 | 2025/01/16 | 9 |
9 | 새로고침 없는 좋아요 버튼 [3] | 2025/01/31 | 9 |
8 | 라이믹스 게시판 스크랩 기능 | 2025/01/21 | 9 |
7 | 글보기에서 바로 비밀글 변경하는 방법 [4] | 2025/01/30 | 10 |
6 | 글추천 버튼 | 2025/01/31 | 10 |
5 | 밍구님의 따뜻한 한마디 | 2025/01/27 | 11 |
4 | [대기] 포인트히스토리 스킨 수정 의뢰 [4] | 2025/01/04 | 12 |