From 74d651afdde3a6200ae752977743b95ff13a8c59 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 9 May 2024 02:26:15 +0900 Subject: [PATCH] Hide category_srl from short URL on document read page --- modules/board/tpl/js/rewrite.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/modules/board/tpl/js/rewrite.js b/modules/board/tpl/js/rewrite.js index 2224e04df..3d9c43b0d 100644 --- a/modules/board/tpl/js/rewrite.js +++ b/modules/board/tpl/js/rewrite.js @@ -1,20 +1,28 @@ 'use strict'; /** - * Remove comment_srl and unnecessary page number from short URL + * Remove unnecessary parameters from short URL. + * + * - category + * - comment_srl + * - page number */ (function() { + var newpath = ''; var match = location.pathname.match(/\/([a-zA-Z0-9_]+)\/([0-9]+)\/(comment|page)\/([0-9]+)$/); if (match && match[1] === window.current_mid) { - var newpath = location.pathname.replace(/\/(comment|page)\/([0-9]+)$/, ''); - if (location.hash && location.hash !== '#') { - newpath += location.hash; - } - if (history.replaceState) { - history.replaceState({ - rx_replaced: true, - prev: location.pathname, - }, '', newpath); - } + newpath = location.pathname.replace(/\/(comment|page)\/([0-9]+)$/, ''); + } + if (location.pathname.match(/\/([0-9]+)$/) && location.search.match(/^\?category=[0-9]+$/)) { + newpath = newpath ? newpath : location.pathname; + } + if (newpath && location.hash && location.hash != '#') { + newpath += location.hash; + } + if (newpath && history.replaceState) { + history.replaceState({ + rx_replaced: true, + prev: location.pathname, + }, '', newpath); } })();