Auto-populate category page titles
Completely remove any need to update things on our side when a Category is added or changed. Will need to inform homepage owners to directly translate the 'label' field, so we don't need to use our translation system.
This commit is contained in:
parent
9b68f936ad
commit
8dedbe88ec
3 changed files with 22 additions and 20 deletions
|
@ -226,8 +226,16 @@ function AppRouter(props: Props) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getDefaultTitle = (pathname: string) => {
|
const getDefaultTitle = (pathname: string) => {
|
||||||
const title = pathname.startsWith('/$/') ? PAGE_TITLE[pathname.substring(3)] : '';
|
let title = '';
|
||||||
return __(title) || (IS_WEB ? SITE_TITLE : 'Odysee');
|
if (pathname.startsWith('/$/')) {
|
||||||
|
const name = pathname.substring(3);
|
||||||
|
if (window.CATEGORY_PAGE_TITLE && window.CATEGORY_PAGE_TITLE[name]) {
|
||||||
|
title = window.CATEGORY_PAGE_TITLE[name];
|
||||||
|
} else {
|
||||||
|
title = PAGE_TITLE[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return __(title) || SITE_TITLE || 'Odysee';
|
||||||
};
|
};
|
||||||
|
|
||||||
if (uri) {
|
if (uri) {
|
||||||
|
|
|
@ -7,24 +7,7 @@ import * as PAGES from 'constants/pages';
|
||||||
|
|
||||||
export const PAGE_TITLE = {
|
export const PAGE_TITLE = {
|
||||||
// --- Categories ---
|
// --- Categories ---
|
||||||
[PAGES.ARTISTS]: 'Artists',
|
// Dynamically populated in 'window.CATEGORY_PAGE_TITLE'.
|
||||||
[PAGES.CREATIVE_ARTS]: 'The Arts',
|
|
||||||
[PAGES.DISCOVER]: 'Wild West',
|
|
||||||
[PAGES.EDUCATION]: 'Education',
|
|
||||||
[PAGES.ENLIGHTENMENT]: 'Enlightenment',
|
|
||||||
[PAGES.FEATURED]: 'Featured',
|
|
||||||
[PAGES.FINANCE]: 'Finance 2.0',
|
|
||||||
[PAGES.GAMING]: 'Gaming',
|
|
||||||
[PAGES.GENERAL]: 'Cheese',
|
|
||||||
[PAGES.LAB]: 'Lab',
|
|
||||||
[PAGES.MOVIES]: 'Movies',
|
|
||||||
[PAGES.MUSIC]: 'Music',
|
|
||||||
[PAGES.NEWS]: 'News & Politics',
|
|
||||||
[PAGES.POP_CULTURE]: 'Pop Culture',
|
|
||||||
[PAGES.SPORTS]: 'Sports',
|
|
||||||
[PAGES.TECH]: 'Tech',
|
|
||||||
[PAGES.UNIVERSE]: 'Universe',
|
|
||||||
[PAGES.WILD_WEST]: 'Wild West',
|
|
||||||
|
|
||||||
// --- Everything else in alphabetical order ---
|
// --- Everything else in alphabetical order ---
|
||||||
[PAGES.BUY]: 'Buy or Swap',
|
[PAGES.BUY]: 'Buy or Swap',
|
||||||
|
|
|
@ -308,6 +308,15 @@ export function doFetchLanguage(language) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function populateCategoryTitles(categories) {
|
||||||
|
if (categories) {
|
||||||
|
window.CATEGORY_PAGE_TITLE = {};
|
||||||
|
Object.values(categories).forEach((x) => {
|
||||||
|
window.CATEGORY_PAGE_TITLE[x.name] = x.label;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function doFetchHomepages() {
|
export function doFetchHomepages() {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
// -- Use this env flag to use local homepage data. Otherwise, it will grab from `/$/api/content/v*/get`.
|
// -- Use this env flag to use local homepage data. Otherwise, it will grab from `/$/api/content/v*/get`.
|
||||||
|
@ -329,6 +338,7 @@ export function doFetchHomepages() {
|
||||||
}
|
}
|
||||||
|
|
||||||
window.homepages = v2;
|
window.homepages = v2;
|
||||||
|
populateCategoryTitles(window.homepages?.en?.categories);
|
||||||
dispatch({ type: ACTIONS.FETCH_HOMEPAGES_DONE });
|
dispatch({ type: ACTIONS.FETCH_HOMEPAGES_DONE });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -339,6 +349,7 @@ export function doFetchHomepages() {
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
if (json?.status === 'success' && json?.data) {
|
if (json?.status === 'success' && json?.data) {
|
||||||
window.homepages = json.data;
|
window.homepages = json.data;
|
||||||
|
populateCategoryTitles(window.homepages?.en?.categories);
|
||||||
dispatch({ type: ACTIONS.FETCH_HOMEPAGES_DONE });
|
dispatch({ type: ACTIONS.FETCH_HOMEPAGES_DONE });
|
||||||
} else {
|
} else {
|
||||||
dispatch({ type: ACTIONS.FETCH_HOMEPAGES_FAILED });
|
dispatch({ type: ACTIONS.FETCH_HOMEPAGES_FAILED });
|
||||||
|
|
Loading…
Reference in a new issue