Skip to content

Commit

Permalink
Merge pull request #960 from WildMeOrg/950_add_meta_description_in_react
Browse files Browse the repository at this point in the history
950 add meta description in react
  • Loading branch information
holmbergius authored Jan 2, 2025
2 parents bc2c8f8 + df0ba8b commit 8811c73
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions frontend/src/hooks/useDocumentTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/ecocean/api/SiteSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 8811c73

Please sign in to comment.