Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

950 add meta description in react #960

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading