From 5fe640c2a30728829fdfbef784032afc64c67a80 Mon Sep 17 00:00:00 2001 From: erinz2020 Date: Thu, 19 Dec 2024 22:35:55 +0000 Subject: [PATCH 1/2] add meta description, author, keywords to react pages --- frontend/src/hooks/useDocumentTitle.js | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/frontend/src/hooks/useDocumentTitle.js b/frontend/src/hooks/useDocumentTitle.js index b1a2192f8c..5008470e01 100644 --- a/frontend/src/hooks/useDocumentTitle.js +++ b/frontend/src/hooks/useDocumentTitle.js @@ -3,10 +3,44 @@ import useGetSiteSettings from "../models/useGetSiteSettings"; export default function useDocumentTitle() { const { data: siteSettings } = useGetSiteSettings(); + + console.log("siteSettings", siteSettings); document.title = siteSettings?.siteName || "wildbook"; useEffect(() => { + if (!siteSettings) return; let iconURL = siteSettings?.siteFavicon; let link = document.querySelector("link[rel*='icon']"); + const metaDescription = document.querySelector("meta[name='description']"); + const metaKeywords = document.querySelector("meta[name='keywords']"); + const metaAuthor = document.querySelector("meta[name='author']"); + + if (!metaDescription) { + const meta = document.createElement("meta"); + meta.name = "description"; + meta.content = siteSettings?.siteDescription; + document.getElementsByTagName("head")[0].appendChild(meta); + } + + if (!metaKeywords) { + const meta = document.createElement("meta"); + meta.name = "keywords"; + meta.content = siteSettings?.siteKeywords; + document.getElementsByTagName("head")[0].appendChild(meta); + } + + if (!metaAuthor) { + const meta = document.createElement("meta"); + meta.name = "author"; + meta.content = siteSettings?.siteAuthor; + document.getElementsByTagName("head")[0].appendChild(meta); + } + + console.log( + "++++++++++++", + siteSettings.siteDescription, + siteSettings.siteKeywords, + siteSettings.siteAuthor, + ); if (link) { link.href = iconURL; From d64c6d12a6f409e6aabdbf69631293a36e763835 Mon Sep 17 00:00:00 2001 From: erinz2020 Date: Fri, 20 Dec 2024 15:11:20 +0000 Subject: [PATCH 2/2] get properties from commonConfiguration --- frontend/src/hooks/useDocumentTitle.js | 8 -------- src/main/java/org/ecocean/api/SiteSettings.java | 3 +++ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/frontend/src/hooks/useDocumentTitle.js b/frontend/src/hooks/useDocumentTitle.js index 5008470e01..a11c8e8053 100644 --- a/frontend/src/hooks/useDocumentTitle.js +++ b/frontend/src/hooks/useDocumentTitle.js @@ -4,7 +4,6 @@ import useGetSiteSettings from "../models/useGetSiteSettings"; export default function useDocumentTitle() { const { data: siteSettings } = useGetSiteSettings(); - console.log("siteSettings", siteSettings); document.title = siteSettings?.siteName || "wildbook"; useEffect(() => { if (!siteSettings) return; @@ -35,13 +34,6 @@ export default function useDocumentTitle() { document.getElementsByTagName("head")[0].appendChild(meta); } - console.log( - "++++++++++++", - siteSettings.siteDescription, - siteSettings.siteKeywords, - siteSettings.siteAuthor, - ); - if (link) { link.href = iconURL; } else { diff --git a/src/main/java/org/ecocean/api/SiteSettings.java b/src/main/java/org/ecocean/api/SiteSettings.java index 898e612eb5..696208dac2 100644 --- a/src/main/java/org/ecocean/api/SiteSettings.java +++ b/src/main/java/org/ecocean/api/SiteSettings.java @@ -47,6 +47,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) // note: there is a CommonConfiguration property: htmlShortcutIcon=images/favicon.ico?v=2 settings.put("siteFavicon", "/images/favicon.ico"); settings.put("siteName", CommonConfiguration.getHTMLTitle(context)); + settings.put("siteDescription", CommonConfiguration.getHTMLDescription(context)); + settings.put("siteKeywords", CommonConfiguration.getHTMLKeywords(context)); + settings.put("siteAuthor", CommonConfiguration.getHTMLAuthor(context)); settings.put("locationData", LocationID.getLocationIDStructure()); settings.put("mapCenterLat", CommonConfiguration.getCenterLat(context));