implement getStaticDir util
This commit is contained in:
parent
934b202114
commit
ce5743f17c
7 changed files with 22 additions and 17 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { setupDateFns } from "@utils/app";
|
import { setupDateFns } from "@utils/app";
|
||||||
|
import { getStaticDir } from "@utils/env";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import process from "process";
|
import process from "process";
|
||||||
|
@ -19,10 +20,7 @@ const [hostname, port] = process.env["LEMMY_UI_HOST"]
|
||||||
|
|
||||||
server.use(express.json());
|
server.use(express.json());
|
||||||
server.use(express.urlencoded({ extended: false }));
|
server.use(express.urlencoded({ extended: false }));
|
||||||
server.use(
|
server.use(getStaticDir(), express.static(path.resolve("./dist")));
|
||||||
`/static/${process.env.COMMIT_HASH}`,
|
|
||||||
express.static(path.resolve("./dist"))
|
|
||||||
);
|
|
||||||
server.use(setCacheControl);
|
server.use(setCacheControl);
|
||||||
|
|
||||||
if (!process.env["LEMMY_UI_DISABLE_CSP"] && !process.env["LEMMY_UI_DEBUG"]) {
|
if (!process.env["LEMMY_UI_DISABLE_CSP"] && !process.env["LEMMY_UI_DEBUG"]) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { getStaticDir } from "@utils/env";
|
||||||
import { Helmet } from "inferno-helmet";
|
import { Helmet } from "inferno-helmet";
|
||||||
import { renderToString } from "inferno-server";
|
import { renderToString } from "inferno-server";
|
||||||
import serialize from "serialize-javascript";
|
import serialize from "serialize-javascript";
|
||||||
|
@ -87,9 +88,7 @@ export async function createSsrHtml(
|
||||||
<link rel="apple-touch-startup-image" href=${appleTouchIcon} />
|
<link rel="apple-touch-startup-image" href=${appleTouchIcon} />
|
||||||
|
|
||||||
<!-- Styles -->
|
<!-- Styles -->
|
||||||
<link rel="stylesheet" type="text/css" href="/static/${
|
<link rel="stylesheet" type="text/css" href="${getStaticDir()}/styles/styles.css" />
|
||||||
process.env.COMMIT_HASH
|
|
||||||
}/styles/styles.css" />
|
|
||||||
|
|
||||||
<!-- Current theme and more -->
|
<!-- Current theme and more -->
|
||||||
${helmet.link.toString() || fallbackTheme}
|
${helmet.link.toString() || fallbackTheme}
|
||||||
|
@ -104,9 +103,7 @@ export async function createSsrHtml(
|
||||||
</noscript>
|
</noscript>
|
||||||
|
|
||||||
<div id='root'>${root}</div>
|
<div id='root'>${root}</div>
|
||||||
<script defer src='/static/${
|
<script defer src='${getStaticDir()}/js/client.js'></script>
|
||||||
process.env.COMMIT_HASH
|
|
||||||
}/js/client.js'></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { getStaticDir } from "@utils/env";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { Component } from "inferno";
|
import { Component } from "inferno";
|
||||||
import { I18NextService } from "../../services";
|
import { I18NextService } from "../../services";
|
||||||
|
@ -23,7 +24,9 @@ export class Icon extends Component<IconProps, any> {
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<use
|
<use
|
||||||
xlinkHref={`/static/${process.env.COMMIT_HASH}/assets/symbols.svg#icon-${this.props.icon}`}
|
xlinkHref={`${getStaticDir()}/assets/symbols.svg#icon-${
|
||||||
|
this.props.icon
|
||||||
|
}`}
|
||||||
></use>
|
></use>
|
||||||
<div className="visually-hidden">
|
<div className="visually-hidden">
|
||||||
<title>{this.props.icon}</title>
|
<title>{this.props.icon}</title>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { showAvatars } from "@utils/app";
|
import { showAvatars } from "@utils/app";
|
||||||
|
import { getStaticDir } from "@utils/env";
|
||||||
import { hostname, isCakeDay } from "@utils/helpers";
|
import { hostname, isCakeDay } from "@utils/helpers";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { Component } from "inferno";
|
import { Component } from "inferno";
|
||||||
|
@ -88,10 +89,7 @@ export class PersonListing extends Component<PersonListingProps, any> {
|
||||||
!this.props.person.banned &&
|
!this.props.person.banned &&
|
||||||
showAvatars() && (
|
showAvatars() && (
|
||||||
<PictrsImage
|
<PictrsImage
|
||||||
src={
|
src={avatar ?? `${getStaticDir()}/assets/icons/icon-96x96.png`}
|
||||||
avatar ??
|
|
||||||
`/static/${process.env.COMMIT_HASH}/assets/icons/icon-96x96.png`
|
|
||||||
}
|
|
||||||
icon
|
icon
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
export const favIconUrl = `/static/${process.env.COMMIT_HASH}/assets/icons/favicon.svg`;
|
import { getStaticDir } from "@utils/env";
|
||||||
export const favIconPngUrl = `/static/${process.env.COMMIT_HASH}/assets/icons/apple-touch-icon.png`;
|
|
||||||
|
export const favIconUrl = `${getStaticDir()}/assets/icons/favicon.svg`;
|
||||||
|
export const favIconPngUrl = `${getStaticDir()}/assets/icons/apple-touch-icon.png`;
|
||||||
|
|
||||||
export const repoUrl = "https://github.com/LemmyNet";
|
export const repoUrl = "https://github.com/LemmyNet";
|
||||||
export const joinLemmyUrl = "https://join-lemmy.org";
|
export const joinLemmyUrl = "https://join-lemmy.org";
|
||||||
|
|
5
src/shared/utils/env/get-static-dir.ts
vendored
Normal file
5
src/shared/utils/env/get-static-dir.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
// Returns path to static directory, intended
|
||||||
|
// for cache-busting based on latest commit hash.
|
||||||
|
export default function getStaticDir() {
|
||||||
|
return `/static/${process.env.COMMIT_HASH}`;
|
||||||
|
}
|
2
src/shared/utils/env/index.ts
vendored
2
src/shared/utils/env/index.ts
vendored
|
@ -6,6 +6,7 @@ import getHttpBaseExternal from "./get-http-base-external";
|
||||||
import getHttpBaseInternal from "./get-http-base-internal";
|
import getHttpBaseInternal from "./get-http-base-internal";
|
||||||
import getInternalHost from "./get-internal-host";
|
import getInternalHost from "./get-internal-host";
|
||||||
import getSecure from "./get-secure";
|
import getSecure from "./get-secure";
|
||||||
|
import getStaticDir from "./get-static-dir";
|
||||||
import httpExternalPath from "./http-external-path";
|
import httpExternalPath from "./http-external-path";
|
||||||
import isHttps from "./is-https";
|
import isHttps from "./is-https";
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ export {
|
||||||
getHttpBaseInternal,
|
getHttpBaseInternal,
|
||||||
getInternalHost,
|
getInternalHost,
|
||||||
getSecure,
|
getSecure,
|
||||||
|
getStaticDir,
|
||||||
httpExternalPath,
|
httpExternalPath,
|
||||||
isHttps,
|
isHttps,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue