align locale theme across sites (#38)
This commit is contained in:
1 parent
9b8db40440
commit
266f2e8bb2
12 files changed
+124
-91
No files matched your search
@@ -1,13 +1,23 @@
|
||||
import { setCookie } from 'typescript-cookie';
|
||||
import { getCookie, setCookie } from 'typescript-cookie';
|
||||
import config from '@/config';
|
||||
import favicon from '@/assets/images/favicon.ico';
|
||||
import { getLocale } from '@/i18n';
|
||||
|
||||
/**
|
||||
* Initialize cookies.
|
||||
*/
|
||||
export const initializeCookies = () => {
|
||||
export const getDomain = () => {
|
||||
const host = window.location.hostname;
|
||||
// process test env and prod env, for example:
|
||||
// hub.acedata.cloud -> .acedata.cloud
|
||||
// hub.test.acedata.cloud -> .acedata.cloud
|
||||
const domain = host.replace(/^\S+?\.(test\.|local\.)?/, '.');
|
||||
console.log('cookies domain', domain);
|
||||
return domain;
|
||||
};
|
||||
|
||||
export const initializeCookies = async () => {
|
||||
// parse the query string and set to cookies
|
||||
const query = new URLSearchParams(window.location.search);
|
||||
|
||||
// set the inviter id to cookies
|
||||
const inviterId = query.get('inviter_id');
|
||||
if (inviterId) {
|
||||
// set the cookie to expire in 7 days
|
||||
@@ -16,7 +26,41 @@ export const initializeCookies = () => {
|
||||
console.log('set INVITER_ID to cookies', inviterId);
|
||||
setCookie('INVITER_ID', inviterId, {
|
||||
expires: expiration,
|
||||
path: '/'
|
||||
path: '/',
|
||||
domain: getDomain()
|
||||
});
|
||||
}
|
||||
|
||||
// set the theme to cookies
|
||||
const theme = query.get('theme');
|
||||
if (theme) {
|
||||
console.log('set THEME to cookies', theme);
|
||||
setCookie('THEME', theme, {
|
||||
path: '/',
|
||||
domain: getDomain()
|
||||
});
|
||||
} else if (!getCookie('THEME')) {
|
||||
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
console.log('set THEME to cookies', isDark ? 'dark' : 'light');
|
||||
setCookie('THEME', isDark ? 'dark' : 'light', {
|
||||
path: '/',
|
||||
domain: getDomain()
|
||||
});
|
||||
}
|
||||
|
||||
// set the locale to cookies
|
||||
const lang = query.get('lang');
|
||||
let locale = undefined;
|
||||
if (lang) {
|
||||
locale = getLocale(lang);
|
||||
} else if (!getCookie('LOCALE')) {
|
||||
locale = getLocale();
|
||||
}
|
||||
if (locale) {
|
||||
console.log('set LOCALE to cookies', locale);
|
||||
setCookie('LOCALE', locale, {
|
||||
path: '/',
|
||||
domain: getDomain()
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -24,7 +68,7 @@ export const initializeCookies = () => {
|
||||
/**
|
||||
* Initialize title.
|
||||
*/
|
||||
export const initializeTitle = () => {
|
||||
export const initializeTitle = async () => {
|
||||
// set the title from config.global.title
|
||||
const title = config.global.title;
|
||||
// find the title element or insert a new one
|
||||
@@ -39,7 +83,7 @@ export const initializeTitle = () => {
|
||||
/**
|
||||
* Initialize favicon.
|
||||
*/
|
||||
export const initializeFavicon = () => {
|
||||
export const initializeFavicon = async () => {
|
||||
// by default use favicon which imported
|
||||
// if faviconUrl is set in config, use it instead
|
||||
const favIconUrl = config.global.faviconUrl;
|
||||
|
||||
Reference in new issue
Block a user