diff --git a/frontend/src/hooks/useDocumentTitle.js b/frontend/src/hooks/useDocumentTitle.js index b1a2192f8c..a11c8e8053 100644 --- a/frontend/src/hooks/useDocumentTitle.js +++ b/frontend/src/hooks/useDocumentTitle.js @@ -3,10 +3,36 @@ import useGetSiteSettings from "../models/useGetSiteSettings"; export default function useDocumentTitle() { const { data: siteSettings } = useGetSiteSettings(); + 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); + } if (link) { link.href = iconURL; 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));