refactor(share): store assets at /share/asset level

This commit is contained in:
Elian Doran 2025-10-24 19:00:26 +03:00
parent 357d294f2d
commit 3660e2f127
No known key found for this signature in database
3 changed files with 8 additions and 8 deletions

View File

@ -7,6 +7,7 @@ async function main() {
// Copy assets // Copy assets
build.copy("src/assets", "assets/"); build.copy("src/assets", "assets/");
build.triggerBuildAndCopyTo("packages/share-theme", "share-theme/assets/");
build.copy("/packages/share-theme/src/templates", "share-theme/templates/"); build.copy("/packages/share-theme/src/templates", "share-theme/templates/");
// Copy node modules dependencies // Copy node modules dependencies

View File

@ -32,6 +32,7 @@ async function register(app: express.Application) {
req.url = `/${assetUrlFragment}` + req.url; req.url = `/${assetUrlFragment}` + req.url;
vite.middlewares(req, res, next); vite.middlewares(req, res, next);
}); });
app.use(`/share/assets/`, express.static(path.join(srcRoot, "../../packages/share-theme/dist")));
} else { } else {
const publicDir = path.join(resourceDir, "public"); const publicDir = path.join(resourceDir, "public");
if (!existsSync(publicDir)) { if (!existsSync(publicDir)) {
@ -42,6 +43,7 @@ async function register(app: express.Application) {
app.use(`/${assetUrlFragment}/stylesheets`, persistentCacheStatic(path.join(publicDir, "stylesheets"))); app.use(`/${assetUrlFragment}/stylesheets`, persistentCacheStatic(path.join(publicDir, "stylesheets")));
app.use(`/${assetUrlFragment}/fonts`, persistentCacheStatic(path.join(publicDir, "fonts"))); app.use(`/${assetUrlFragment}/fonts`, persistentCacheStatic(path.join(publicDir, "fonts")));
app.use(`/${assetUrlFragment}/translations/`, persistentCacheStatic(path.join(publicDir, "translations"))); app.use(`/${assetUrlFragment}/translations/`, persistentCacheStatic(path.join(publicDir, "translations")));
app.use(`/share/assets/`, persistentCacheStatic(path.join(resourceDir, "share-theme/assets")));
app.use(`/node_modules/`, persistentCacheStatic(path.join(publicDir, "node_modules"))); app.use(`/node_modules/`, persistentCacheStatic(path.join(publicDir, "node_modules")));
} }
app.use(`/${assetUrlFragment}/images`, persistentCacheStatic(path.join(resourceDir, "assets", "images"))); app.use(`/${assetUrlFragment}/images`, persistentCacheStatic(path.join(resourceDir, "assets", "images")));

View File

@ -9,15 +9,13 @@ import type BBranch from "../becca/entities/bbranch.js";
import { t } from "i18next"; import { t } from "i18next";
import SBranch from "./shaca/entities/sbranch.js"; import SBranch from "./shaca/entities/sbranch.js";
import options from "../services/options.js"; import options from "../services/options.js";
import utils, { getResourceDir, isDev, safeExtractMessageAndStackFromError } from "../services/utils.js"; import utils, { isDev, safeExtractMessageAndStackFromError } from "../services/utils.js";
import app_path from "../services/app_path.js";
import ejs from "ejs"; import ejs from "ejs";
import log from "../services/log.js"; import log from "../services/log.js";
import { join } from "path"; import { join } from "path";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`; const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`;
const shareAdjustedAppPath = isDev ? app_path : `../${app_path}`;
const templateCache: Map<string, string> = new Map(); const templateCache: Map<string, string> = new Map();
/** /**
@ -99,9 +97,9 @@ export function renderNoteContent(note: SNote) {
// Determine CSS to load. // Determine CSS to load.
const cssToLoad: string[] = []; const cssToLoad: string[] = [];
if (!isDev && !note.isLabelTruthy("shareOmitDefaultCss")) { if (!note.isLabelTruthy("shareOmitDefaultCss")) {
cssToLoad.push(`${shareAdjustedAssetPath}/src/share.css`); cssToLoad.push(`assets/styles.css`);
cssToLoad.push(`${shareAdjustedAssetPath}/src/boxicons.css`); cssToLoad.push(`assets/boxicons.css`);
} }
for (const cssRelation of note.getRelations("shareCss")) { for (const cssRelation of note.getRelations("shareCss")) {
cssToLoad.push(`api/notes/${cssRelation.value}/download`); cssToLoad.push(`api/notes/${cssRelation.value}/download`);
@ -109,7 +107,7 @@ export function renderNoteContent(note: SNote) {
// Determine JS to load. // Determine JS to load.
const jsToLoad: string[] = [ const jsToLoad: string[] = [
`${shareAdjustedAppPath}/share.js` "assets/scripts.js"
]; ];
for (const jsRelation of note.getRelations("shareJs")) { for (const jsRelation of note.getRelations("shareJs")) {
jsToLoad.push(`api/notes/${jsRelation.value}/download`); jsToLoad.push(`api/notes/${jsRelation.value}/download`);
@ -147,7 +145,6 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)
isEmpty, isEmpty,
assetPath: shareAdjustedAssetPath, assetPath: shareAdjustedAssetPath,
assetUrlFragment, assetUrlFragment,
appPath: shareAdjustedAppPath,
showLoginInShareTheme, showLoginInShareTheme,
t, t,
isDev, isDev,