A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix: template adds logo to distinguish html source #895
shuaibfe04cfa246f
diff --git a/ui/src/components/Customize/index.tsx b/ui/src/components/Customize/index.tsxindex aa233678..c02db675 100644--- a/ui/src/components/Customize/index.tsx+++ b/ui/src/components/Customize/index.tsx@@ -53,9 +53,7 @@ const ActivateScriptNodes = (el, part) => {}scriptList?.forEach((so) => {const script = document.createElement('script');- script.text = `(() => {- ${so.text}- })();`;+ script.text = `(() => {${so.text}})();`;for (let i = 0; i < so.attributes.length; i += 1) {const attr = so.attributes[i];script.setAttribute(attr.name, attr.value);@@ -68,7 +66,6 @@ type pos = 'afterbegin' | 'beforeend';const renderCustomArea = (el, part, pos: pos, content: string = '') => {let startMarkNode;let endMarkNode;- let accumulatedContent = ''; //const { childNodes } = el;for (let i = 0; i < childNodes.length; i += 1) {const node = childNodes[i];@@ -82,29 +79,6 @@ const renderCustomArea = (el, part, pos: pos, content: string = '') => {}}- // Iterate over all nodes between startMarkNode and endMarkNode.- if (startMarkNode && endMarkNode) {- let contentNode = startMarkNode.nextSibling;- while (contentNode && contentNode !== endMarkNode) {- if (contentNode.nodeType === 1) {- // element node- accumulatedContent += contentNode.outerHTML;- } else if (contentNode.nodeType === 3) {- // text node- accumulatedContent += contentNode.textContent;- }- contentNode = contentNode.nextSibling;- }- }-- console.log('====', accumulatedContent);-- // 比较累积的内容和指定的内容- if (accumulatedContent.includes(content)) {- console.log('Content already exists. No insertion needed.');- return;- }-if (startMarkNode && endMarkNode) {while (startMarkNode.nextSibling &&@@ -131,7 +105,6 @@ const handleCustomHead = (content) => {const handleCustomHeader = (content) => {const el = document.body;- console.log('====11', content);renderCustomArea(el, CUSTOM_MARK_HEADER, 'afterbegin', content);};@@ -145,11 +118,14 @@ const Index: FC = () => {(state) => state,);useEffect(() => {- setTimeout(() => {- handleCustomHead(custom_head);- }, 1000);- handleCustomHeader(custom_header);- handleCustomFooter(custom_footer);+ const isSeo = document.querySelector('meta[name="go-template"]');+ if (!isSeo) {+ setTimeout(() => {+ handleCustomHead(custom_head);+ }, 1000);+ handleCustomHeader(custom_header);+ handleCustomFooter(custom_footer);+ }}, [custom_head, custom_header, custom_footer]);return null;};diff --git a/ui/template/header.html b/ui/template/header.htmlindex 25741bf4..6eff7340 100644--- a/ui/template/header.html+++ b/ui/template/header.html@@ -76,6 +76,7 @@name="twitter:image"content="{{if $.siteinfo.Branding.Favicon }}{{$.siteinfo.Branding.Favicon}}{{else}}{{$.baseURL}}/favicon.ico{{end}}"}/>+ <meta name="go-template"><!--customize_head-->{{if .HeadCode }} {{.HeadCode | templateHTML}} {{end}}<!--customize_head-->