Admin Panel/Settings/Layout, for PWA: Custom head meta, link, icons, assetlinks.json, site.webmanifest.

Thanks to xet7 !
This commit is contained in:
Lauri Ojansivu 2026-02-15 21:49:55 +02:00
parent dace6b78c0
commit b5a13f0206
16 changed files with 1016 additions and 3 deletions

View file

@ -48,6 +48,10 @@ import './migrations/comprehensiveBoardMigration';
// Import file serving routes
import './routes/universalFileServer';
import './routes/customHeadAssets';
// Import server-side custom head rendering
import './lib/customHeadRender';
// Note: Automatic migrations are disabled - migrations only run when opening boards
// import './boardMigrationDetector';

View file

@ -0,0 +1,54 @@
import { WebApp } from 'meteor/webapp';
import { WebAppInternals } from 'meteor/webapp';
import Settings from '/models/settings';
Meteor.startup(() => {
// Use Meteor's official API to modify the HTML boilerplate
WebAppInternals.registerBoilerplateDataCallback('wekan-custom-head', (request, data) => {
try {
const setting = Settings.findOne();
// Initialize head array if it doesn't exist
if (!data.head) {
data.head = '';
}
// Always set title tag based on productName
const productName = (setting && setting.productName) ? setting.productName : 'Wekan';
data.head += `\n <title>${productName}</title>\n`;
// Only add custom head tags if enabled
if (!setting || !setting.customHeadEnabled) {
return data;
}
let injection = '';
// Add custom link tags (except manifest if custom manifest is enabled)
if (setting.customHeadLinkTags && setting.customHeadLinkTags.trim()) {
let linkTags = setting.customHeadLinkTags;
if (setting.customManifestEnabled) {
// Remove any manifest links from custom link tags to avoid duplicates
linkTags = linkTags.replace(/<link[^>]*rel=["\']?manifest["\']?[^>]*>/gi, '');
}
if (linkTags.trim()) {
injection += linkTags + '\n';
}
}
// Add manifest link if custom manifest is enabled
if (setting.customManifestEnabled) {
injection += ' <link rel="manifest" href="/site.webmanifest" crossorigin="use-credentials">\n';
}
if (injection.trim()) {
// Append custom head content to the existing head
data.head += injection;
}
return data;
} catch (e) {
console.error('[Custom Head] Error in boilerplate callback:', e.message, e.stack);
return data;
}
});
});

View file

@ -38,6 +38,13 @@ Meteor.publish('setting', () => {
oidcBtnText: 1,
mailDomainName: 1,
legalNotice: 1,
customHeadEnabled: 1,
customHeadMetaTags: 1,
customHeadLinkTags: 1,
customManifestEnabled: 1,
customManifestContent: 1,
customAssetLinksEnabled: 1,
customAssetLinksContent: 1,
accessibilityPageEnabled: 1,
accessibilityTitle: 1,
accessibilityContent: 1,

View file

@ -0,0 +1,81 @@
import { WebApp } from 'meteor/webapp';
import { Meteor } from 'meteor/meteor';
import fs from 'fs';
import path from 'path';
import Settings from '/models/settings';
const shouldServeContent = (value) =>
typeof value === 'string' && value.trim().length > 0;
const getDefaultFileContent = (filename) => {
try {
const filePath = path.join(Meteor.absolutePath, 'public', filename);
if (fs.existsSync(filePath)) {
return fs.readFileSync(filePath, 'utf-8');
}
} catch (e) {
console.error(`Error reading default file ${filename}:`, e);
}
return null;
};
const respondWithText = (res, contentType, body) => {
res.writeHead(200, {
'Content-Type': `${contentType}; charset=utf-8`,
'Access-Control-Allow-Origin': '*',
});
res.end(body);
};
WebApp.connectHandlers.use('/site.webmanifest', (req, res, next) => {
if (req.method !== 'GET' && req.method !== 'HEAD') return next();
const setting = Settings.findOne(
{},
{
fields: {
customHeadEnabled: 1,
customManifestEnabled: 1,
customManifestContent: 1,
},
},
);
// Serve custom content if enabled
if (setting && setting.customHeadEnabled && setting.customManifestEnabled && shouldServeContent(setting.customManifestContent)) {
return respondWithText(res, 'application/manifest+json', setting.customManifestContent);
}
// Fallback to default manifest file
const defaultContent = getDefaultFileContent('site.webmanifest.default');
if (defaultContent) {
return respondWithText(res, 'application/manifest+json', defaultContent);
}
return next();
});
WebApp.connectHandlers.use('/.well-known/assetlinks.json', (req, res, next) => {
if (req.method !== 'GET' && req.method !== 'HEAD') return next();
const setting = Settings.findOne(
{},
{
fields: {
customAssetLinksEnabled: 1,
customAssetLinksContent: 1,
},
},
);
// Serve custom content if enabled
if (setting && setting.customAssetLinksEnabled && shouldServeContent(setting.customAssetLinksContent)) {
return respondWithText(res, 'application/json', setting.customAssetLinksContent);
}
// Fallback to default assetlinks file
const defaultContent = getDefaultFileContent('.well-known/assetlinks.json.default');
if (defaultContent) {
return respondWithText(res, 'application/json', defaultContent);
}
return next();
});