Use helmet for theme inclusion instead
This commit is contained in:
parent
ed5c4c1123
commit
b8a47be3df
3 changed files with 41 additions and 20 deletions
|
@ -61,17 +61,6 @@ server.get('/*', async (req, res) => {
|
|||
};
|
||||
|
||||
initializeSite(site);
|
||||
const user = site.my_user;
|
||||
const userTheme =
|
||||
user &&
|
||||
user.theme &&
|
||||
`
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
href="/static/assets/css/themes/${user.theme}.min.css"
|
||||
/>
|
||||
`;
|
||||
|
||||
const wrapper = (
|
||||
<StaticRouter location={req.url} context={isoData}>
|
||||
|
@ -93,7 +82,6 @@ server.get('/*', async (req, res) => {
|
|||
|
||||
${helmet.title.toString()}
|
||||
${helmet.meta.toString()}
|
||||
${helmet.link.toString()}
|
||||
|
||||
<!-- Required meta tags -->
|
||||
<meta name="Description" content="Lemmy">
|
||||
|
@ -109,13 +97,9 @@ server.get('/*', async (req, res) => {
|
|||
|
||||
<!-- Styles -->
|
||||
<link rel="stylesheet" type="text/css" href="/static/styles/styles.css" />
|
||||
${
|
||||
userTheme ??
|
||||
`
|
||||
<link rel="stylesheet" type="text/css" href="/static/assets/css/themes/litely.min.css" id="default-light" media="(prefers-color-scheme: light)" />
|
||||
<link rel="stylesheet" type="text/css" href="/static/assets/css/themes/darkly.min.css" id="default-dark" media="(prefers-color-scheme: no-preference), (prefers-color-scheme: dark)" />
|
||||
`.trim()
|
||||
}
|
||||
|
||||
<!-- Current theme and more -->
|
||||
${helmet.link.toString()}
|
||||
</head>
|
||||
|
||||
<body ${helmet.bodyAttributes.toString()}>
|
||||
|
|
|
@ -6,9 +6,9 @@ import { i18n } from '../i18next';
|
|||
import { routes } from '../../shared/routes';
|
||||
import { Navbar } from '../../shared/components/navbar';
|
||||
import { Footer } from '../../shared/components/footer';
|
||||
import { Theme } from './theme';
|
||||
import { Symbols } from '../../shared/components/symbols';
|
||||
import { GetSiteResponse } from 'lemmy-js-client';
|
||||
import { UserService } from '../../shared/services';
|
||||
import './styles.scss';
|
||||
|
||||
export interface AppProps {
|
||||
|
@ -24,6 +24,7 @@ export class App extends Component<AppProps, any> {
|
|||
<>
|
||||
<Provider i18next={i18n}>
|
||||
<div>
|
||||
<Theme user={this.props.site.my_user} />
|
||||
{this.props.site &&
|
||||
this.props.site.site &&
|
||||
this.props.site.site.icon && (
|
||||
|
|
36
src/shared/components/theme.tsx
Normal file
36
src/shared/components/theme.tsx
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { User } from 'lemmy-js-client';
|
||||
import { Helmet } from 'inferno-helmet';
|
||||
|
||||
export const Theme = (props: { user: User | undefined }) => {
|
||||
const user = props.user;
|
||||
const userTheme = user && user.theme && (
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
href={`/static/assets/css/themes/${user.theme}.min.css`}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<Helmet>
|
||||
{userTheme ?? (
|
||||
<>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
href="/static/assets/css/themes/litely.min.css"
|
||||
id="default-light"
|
||||
media="(prefers-color-scheme: light)"
|
||||
/>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
href="/static/assets/css/themes/darkly.min.css"
|
||||
id="default-dark"
|
||||
media="(prefers-color-scheme: no-preference), (prefers-color-scheme: dark)"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Helmet>
|
||||
);
|
||||
};
|
Loading…
Reference in a new issue