Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Server Default Appearances #4478

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ let needSetup = false;
const statusPageRouter = require("./routers/status-page-router");
app.use(statusPageRouter);

const { injectDefaultAppearance } = require("./utils/inject-default-appearance");
app.use(injectDefaultAppearance);

// Universal Route Handler, must be at the end of all express routes.
app.get("*", async (_request, response) => {
if (_request.originalUrl.startsWith("/upload/")) {
Expand Down
50 changes: 50 additions & 0 deletions server/utils/inject-default-appearance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { Settings } = require("../settings");
const cheerio = require("cheerio");
const jsesc = require("jsesc");
const { log } = require("../../src/util");

const injectDefaultAppearance = (req, res, next) => {

try {
// Intercept send() calls and inject Default Appearance
// https://stackoverflow.com/a/60817116
const oldSend = res.send;
res.send = async (data) => {

if (typeof data === "string") {
log.debug("inject-default-appearance", req.method + " " + req.url);
const $ = cheerio.load(data);

const defaultAppearance = await Settings.get("defaultAppearance");
if (defaultAppearance) {
const head = $("head");

const escapedJSONObject = jsesc(defaultAppearance, { isScriptContext: true });

const script = $(`
<script id="default-appearance" data-json="{}">
window.defaultAppearance = ${escapedJSONObject};
</script>
`);

head.append(script);

data = $.root().html();
}
}

res.send = oldSend; // set function back to avoid 'double-send'
return res.send(data);
};

next();
} catch (e) {

next(e);
}

};

module.exports = {
injectDefaultAppearance
};
73 changes: 73 additions & 0 deletions src/components/HorizontalTabHeader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<template>
<div>
<ul class="nav nav-tabs">
<li v-for="(tab, index) in tabs" :key="index" class="nav-item">
<a
class="nav-link"
:class="{ active: index == selected }"
href="#"
@click="$emit('update:selected', index)"
>
{{ tab }}
</a>
</li>
</ul>
</div>
</template>

<script lang="js">
export default {
props: {
tabs: {
type: Array[String],
required: true,
},
selected: {
type: Number,
required: true,
},
},
emits: [ "update:selected" ],
data() {
return {};
},
};
</script>

<style lang="scss" scoped>
@import "../assets/vars.scss";

.nav-tabs {
border-bottom: 1px solid $primary;

.nav-item {
flex-grow: 1;

.nav-link {
text-align: center;
border-top-left-radius: 10px;
border-top-right-radius: 10px;

&.active {
background-color: $highlight-white;

.dark & {
color: $dark-font-color;
background-color: $dark-header-bg;
}

border-color: transparent transparent $primary transparent;
border-width: 1px 1px 6px 1px;
}

&:hover {
.dark & {
background-color: $dark-header-bg;
}
border-color: $primary;
border-width: 1px 1px 6px 1px;
}
}
}
}
</style>
Loading
Loading