Skip to content

Commit 9e2cc7d

Browse files
committed
update theme to resolved missing fonts
also add harmony client side modules
1 parent 7c41ac2 commit 9e2cc7d

File tree

5 files changed

+224
-5
lines changed

5 files changed

+224
-5
lines changed

lib/controllers.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const Controllers = module.exports;
4+
5+
const accountHelpers = require.main.require('./src/controllers/accounts/helpers');
6+
const helpers = require.main.require('./src/controllers/helpers');
7+
8+
Controllers.renderAdminPage = (req, res) => {
9+
res.render('admin/plugins/theme-quickstart', {
10+
title: 'Quick Start Theme',
11+
});
12+
};
13+
14+
Controllers.renderThemeSettings = async (req, res, next) => {
15+
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
16+
if (!userData) {
17+
return next();
18+
}
19+
const lib = require('./theme');
20+
userData.theme = await lib.loadThemeConfig(userData.uid);
21+
22+
userData.title = '[[themes/harmony:settings.title]]';
23+
userData.breadcrumbs = helpers.buildBreadcrumbs([
24+
{ text: userData.username, url: `/user/${userData.userslug}` },
25+
{ text: '[[themes/harmony:settings.title]]' },
26+
]);
27+
28+
res.render('account/theme', userData);
29+
};

lib/theme.js

+126-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,84 @@
1-
21
'use strict';
32

4-
const Theme = module.exports;
3+
const nconf = require.main.require('nconf');
4+
const meta = require.main.require('./src/meta');
5+
const _ = require.main.require('lodash');
6+
const user = require.main.require('./src/user');
7+
8+
const controllers = require('./controllers');
9+
10+
const library = module.exports;
11+
12+
const defaults = {
13+
enableQuickReply: 'on',
14+
centerHeaderElements: 'off',
15+
mobileTopicTeasers: 'off',
16+
stickyToolbar: 'on',
17+
autohideBottombar: 'on',
18+
openSidebars: 'off',
19+
chatModals: 'off',
20+
};
21+
22+
library.init = async function (params) {
23+
const { router, middleware } = params;
24+
const routeHelpers = require.main.require('./src/routes/helpers');
25+
26+
routeHelpers.setupAdminPageRoute(router, '/admin/plugins/theme-quickstart', [], controllers.renderAdminPage);
27+
28+
routeHelpers.setupPageRoute(router, '/user/:userslug/theme', [
29+
middleware.exposeUid,
30+
middleware.ensureLoggedIn,
31+
middleware.canViewUsers,
32+
middleware.checkAccountPermissions,
33+
], controllers.renderThemeSettings);
34+
35+
if (nconf.get('isPrimary') && process.env.NODE_ENV === 'production') {
36+
setTimeout(buildSkins, 0);
37+
}
38+
};
39+
40+
async function buildSkins() {
41+
try {
42+
const plugins = require.main.require('./src/plugins');
43+
await plugins.prepareForBuild(['client side styles']);
44+
for (const skin of meta.css.supportedSkins) {
45+
// eslint-disable-next-line no-await-in-loop
46+
await meta.css.buildBundle(`client-${skin}`, true);
47+
}
48+
require.main.require('./src/meta/minifier').killAll();
49+
} catch (err) {
50+
console.error(err.stack);
51+
}
52+
}
53+
54+
library.addAdminNavigation = async function (header) {
55+
header.plugins.push({
56+
route: '/plugins/theme-quickstart',
57+
icon: 'fa-paint-brush',
58+
name: 'Theme Quick Start',
59+
});
60+
return header;
61+
};
62+
63+
library.addProfileItem = async (data) => {
64+
data.links.push({
65+
id: 'theme',
66+
route: 'theme',
67+
icon: 'fa-paint-brush',
68+
name: '[[themes/harmony:settings.title]]',
69+
visibility: {
70+
self: true,
71+
other: false,
72+
moderator: false,
73+
globalMod: false,
74+
admin: false,
75+
},
76+
});
77+
78+
return data;
79+
};
580

6-
Theme.defineWidgetAreas = async function (areas) {
81+
library.defineWidgetAreas = async function (areas) {
782
const locations = ['header', 'sidebar', 'footer'];
883
const templates = [
984
'categories.tpl', 'category.tpl', 'topic.tpl', 'users.tpl',
@@ -63,3 +138,51 @@ Theme.defineWidgetAreas = async function (areas) {
63138

64139
return areas;
65140
};
141+
142+
library.loadThemeConfig = async function (uid) {
143+
const [themeConfig, userConfig] = await Promise.all([
144+
meta.settings.get('harmony'),
145+
user.getSettings(uid),
146+
]);
147+
148+
const config = { ...defaults, ...themeConfig, ...(_.pick(userConfig, Object.keys(defaults))) };
149+
config.enableQuickReply = config.enableQuickReply === 'on';
150+
config.centerHeaderElements = config.centerHeaderElements === 'on';
151+
config.mobileTopicTeasers = config.mobileTopicTeasers === 'on';
152+
config.stickyToolbar = config.stickyToolbar === 'on';
153+
config.autohideBottombar = config.autohideBottombar === 'on';
154+
config.openSidebars = config.openSidebars === 'on';
155+
config.chatModals = config.chatModals === 'on';
156+
return config;
157+
};
158+
159+
library.getThemeConfig = async function (config) {
160+
config.theme = await library.loadThemeConfig(config.uid);
161+
config.openDraftsOnPageLoad = false;
162+
return config;
163+
};
164+
165+
library.getAdminSettings = async function (hookData) {
166+
if (hookData.plugin === 'harmony') {
167+
hookData.values = {
168+
...defaults,
169+
...hookData.values,
170+
};
171+
}
172+
return hookData;
173+
};
174+
175+
library.saveUserSettings = async function (hookData) {
176+
Object.keys(defaults).forEach((key) => {
177+
if (hookData.data.hasOwnProperty(key)) {
178+
hookData.settings[key] = hookData.data[key] || undefined;
179+
}
180+
});
181+
return hookData;
182+
};
183+
184+
library.filterMiddlewareRenderHeader = async function (hookData) {
185+
hookData.templateData.bootswatchSkinOptions = await meta.css.getSkinSwitcherOptions(hookData.req.uid);
186+
return hookData;
187+
};
188+

plugin.json

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
{
22
"id": "nodebb-theme-quickstart",
33
"hooks": [
4-
{ "hook": "filter:widgets.getAreas", "method": "defineWidgetAreas" }
4+
{ "hook": "static:app.load", "method": "init" },
5+
{ "hook": "filter:admin.header.build", "method": "addAdminNavigation" },
6+
{ "hook": "filter:widgets.getAreas", "method": "defineWidgetAreas" },
7+
{ "hook": "filter:config.get", "method": "getThemeConfig" },
8+
{ "hook": "filter:settings.get", "method": "getAdminSettings"},
9+
{ "hook": "filter:user.saveSettings", "method": "saveUserSettings" },
10+
{ "hook": "filter:user.profileMenu", "method": "addProfileItem" },
11+
{ "hook": "filter:middleware.renderHeader", "method": "filterMiddlewareRenderHeader" }
512
],
613
"scripts": [
714
"public/client.js",
815
"../nodebb-theme-harmony/public/harmony.js"
916
],
1017
"templates": "templates",
1118
"modules": {
12-
19+
"../admin/plugins/theme-quickstart.js": "../nodebb-theme-harmony/public/admin.js",
20+
"../client/account/theme.js": "../nodebb-theme-harmony/public/settings.js"
21+
},
22+
"staticDirs": {
23+
"inter": "node_modules/@fontsource/inter/files",
24+
"poppins": "node_modules/@fontsource/poppins/files"
1325
}
1426
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<div class="acp-page-container">
2+
<!-- IMPORT admin/partials/settings/header.tpl -->
3+
4+
<div class="row m-0">
5+
<div id="spy-container" class="col-12 col-md-8 px-0 mb-4" tabindex="0">
6+
<form role="form" class="harmony-settings">
7+
<div class="form-check form-switch">
8+
<input type="checkbox" class="form-check-input" id="enableQuickReply" name="enableQuickReply" />
9+
<label for="enableQuickReply" class="form-check-label">[[themes/harmony:settings.enableQuickReply]]</label>
10+
</div>
11+
<div class="form-check form-switch">
12+
<input type="checkbox" class="form-check-input" id="centerHeaderElements" name="centerHeaderElements" />
13+
<label for="centerHeaderElements" class="form-check-label">[[themes/harmony:settings.centerHeaderElements]]</label>
14+
</div>
15+
<div class="form-check form-switch">
16+
<input type="checkbox" class="form-check-input" id="mobileTopicTeasers" name="mobileTopicTeasers" />
17+
<label for="mobileTopicTeasers" class="form-check-label">[[themes/harmony:settings.mobileTopicTeasers]]</label>
18+
</div>
19+
<div class="form-check form-switch">
20+
<input type="checkbox" class="form-check-input" id="stickyToolbar" name="stickyToolbar" />
21+
<div for="stickyToolbar" class="form-check-label">
22+
[[themes/harmony:settings.stickyToolbar]]
23+
<p class="form-text">
24+
[[themes/harmony:settings.stickyToolbar.help]]
25+
</p>
26+
</div>
27+
</div>
28+
<div class="form-check form-switch">
29+
<input type="checkbox" class="form-check-input" id="autohideBottombar" name="autohideBottombar" />
30+
<div for="autohideBottombar" class="form-check-label">
31+
[[themes/harmony:settings.autohideBottombar]]
32+
<p class="form-text">
33+
[[themes/harmony:settings.autohideBottombar.help]]
34+
</p>
35+
</div>
36+
</div>
37+
<div class="form-check form-switch">
38+
<input type="checkbox" class="form-check-input" id="openSidebars" name="openSidebars" />
39+
<label for="openSidebars" class="form-check-label">[[themes/harmony:settings.openSidebars]]</label>
40+
</div>
41+
<div class="form-check form-switch">
42+
<input type="checkbox" class="form-check-input" id="chatModals" name="chatModals" />
43+
<div for="chatModals" class="form-check-label">
44+
[[themes/harmony:settings.chatModals]]
45+
</div>
46+
</div>
47+
</form>
48+
</div>
49+
50+
<!-- IMPORT admin/partials/settings/toc.tpl -->
51+
</div>
52+
</div>

theme.scss

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
// override harmony font-path
2+
$font-path: "./plugins/nodebb-theme-quickstart";
3+
14
@import "../nodebb-theme-harmony/theme";

0 commit comments

Comments
 (0)