Skip to content

Commit f08fef7

Browse files
committed
feat(customPageSettings): 添加自定义页面内容
1 parent 08b1766 commit f08fef7

File tree

8 files changed

+77
-16
lines changed

8 files changed

+77
-16
lines changed

src/baseTypes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ export interface InvioPluginSettings {
112112
logToDB?: boolean;
113113
skipSizeLargerThan?: number;
114114

115+
customFooter?: string;
116+
customStyle?: string;
117+
115118
/**
116119
* @deprecated
117120
*/

src/exporter.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MarkdownView, Notice, TFile, TFolder } from 'obsidian';
44
// modules that are part of the plugin
55
import { InvioSettingTab } from './settings';
66
import { Utils } from './utils/utils';
7-
import { HTMLGenerator } from './html-generation/html-generator';
7+
import { HTMLGenerator, ICustomPageSettings } from './html-generation/html-generator';
88
import { Path } from './utils/path';
99
import { ExportFile } from './html-generation/export-file';
1010
import { AssetHandler } from './html-generation/asset-handler';
@@ -21,7 +21,8 @@ export const exportFile = async (
2121
exportToPath: Path | undefined = undefined,
2222
rootPath: Path | undefined,
2323
view: StatsView,
24-
remoteClient?: RemoteClient
24+
remoteClient?: RemoteClient,
25+
settings?: InvioPluginSettings
2526
) : Promise<ExportFile | undefined> => {
2627
if(file.extension != "md")
2728
{
@@ -48,7 +49,8 @@ export const exportFile = async (
4849
const { s3BucketName: bucket, s3Endpoint: endpoint } = remoteClient.s3Config;
4950
remoteCOSDomain = `https://${bucket}.${endpoint}/`;
5051
}
51-
await HTMLGenerator.generateWebpage(exportedFile, rootPath, view, remoteCOSDomain);
52+
const customPageSettings: ICustomPageSettings = { footer: settings.customFooter, style: settings.customStyle };
53+
await HTMLGenerator.generateWebpage(exportedFile, rootPath, view, remoteCOSDomain, customPageSettings);
5254
}
5355
catch (e)
5456
{
@@ -114,7 +116,7 @@ export const publishFiles = async (
114116
// RenderLog.progress(i++, path.length, "Exporting Docs", "Exporting: " + file.path, "var(--color-accent)");
115117
view?.info("Exporting: " + file.path);
116118

117-
const exportedFile = await exportFile(file, new Path(path), htmlFilePath, new Path(client.getUseHostSlug()), view, client);
119+
const exportedFile = await exportFile(file, new Path(path), htmlFilePath, new Path(client.getUseHostSlug()), view, client, settings);
118120
if (exportedFile) {
119121
log.info('exported file downloads: ', exportedFile.downloads);
120122
externalFiles.push(...exportedFile.downloads.map((d: Downloadable) => {

src/html-generation/html-generator.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import { log } from "../moreOnLog";
1010
import { StatsView } from "src/statsView";
1111
import InvioPlugin from "src/main";
1212
import { Utils } from "src/utils/utils";
13-
import { WMS_FOOTER, WMS_FOOTER_STYLE } from './wms-footer';
1413

14+
export interface ICustomPageSettings {
15+
footer?: string;
16+
style?: string;
17+
}
1518
const LogoSVGDefault = `<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="svg238067" height="768px" width="1024px" version="1.1" viewBox="0 0 100 100" class="svg-icon invio-sync-wait"><g fill-rule="evenodd" style="transform: scale3d(0.89, 0.99, 1.5);"><path d="M27 97.93A56.08 56.08 0 0 1 9.29 19.08 55.77 55.77 0 0 0 23.59 50l.07.07c.53.58 1.06 1.14 1.62 1.7s1.12 1.09 1.72 1.62L45.54 72a14.93 14.93 0 0 1 4.53 10.93v1.59a15.12 15.12 0 0 1-8 13.52A15.09 15.09 0 0 1 27 97.93z" style="fill: var(--icon-color);"></path><path d="M23.59 50a55.77 55.77 0 0 1-14.3-30.92A56.46 56.46 0 0 1 27 2.08 15.08 15.08 0 0 1 42.11 2a15.12 15.12 0 0 1 8 13.52v1.59A15 15 0 0 1 45.55 28l-22 22z" fill="#999999" opacity=".8"></path><path d="M85.16 2.08a56.08 56.08 0 0 1 17.67 78.84A55.77 55.77 0 0 0 88.53 50l-.08-.07c-.52-.58-1.06-1.14-1.62-1.7s-1.12-1.09-1.69-1.62L66.58 28a14.93 14.93 0 0 1-4.53-10.93v-1.55A15.12 15.12 0 0 1 70 2a15.08 15.08 0 0 1 15.15.08z" style="fill: var(--icon-color);"></path><path d="M88.53 50a55.77 55.77 0 0 1 14.3 30.92 56.35 56.35 0 0 1-17.67 17 15.46 15.46 0 0 1-23.11-13.44v-1.59A15 15 0 0 1 66.57 72l22-22z" fill="#999999" opacity=".8"></path></g></svg>`
1619

1720
export interface IMetaConfig {
@@ -77,11 +80,12 @@ export class HTMLGenerator {
7780
rootPath: Path,
7881
view: StatsView,
7982
remoteDomain?: string, // website assets file's host domain
83+
customPageSettings?: ICustomPageSettings
8084
): Promise<ExportFile> {
8185
await this.getDocumentHTML(file, rootPath, false, view, remoteDomain);
8286
let usingDocument = file.document;
8387

84-
let sidebars = this.generateSideBars(file.contentElement, file);
88+
let sidebars = this.generateSideBars(file.contentElement, file, customPageSettings);
8589
this.generateSideBarBtns(file, sidebars);
8690
let rightSidebar = sidebars.right;
8791
let leftSidebar = sidebars.left;
@@ -146,6 +150,7 @@ export class HTMLGenerator {
146150
file.downloads.push(new Downloadable('_common-left-tree.html', fileTree.outerHTML, rootDir));
147151
// TODO: 摆脱includeFileTree限制,定制优化index首页UI样式
148152
if (InvioSettingTab.settings.generateIndexPage) {
153+
const customFooter = customPageSettings.footer ? `<div class="tree-footer">${customPageSettings.footer}</div>` : ''
149154
const indexPageHTML = `<!DOCTYPE html><html lang="zh"><head>
150155
<title>${prefix}</title>
151156
<style>
@@ -171,9 +176,9 @@ export class HTMLGenerator {
171176
display: none;
172177
}
173178
.tree-scroll-area>.tree-item>.tree-item-contents { padding: 1rem; text-align: center; }
174-
${WMS_FOOTER_STYLE}
179+
${customPageSettings.style || ''}
175180
</style>
176-
</head><body>${fileTree.outerHTML}<div class="tree-footer">${WMS_FOOTER}</div></body></html>`;
181+
</head><body>${fileTree.outerHTML}${customFooter}</body></html>`;
177182
file.downloads.push(new Downloadable('index.html', indexPageHTML, rootDir));
178183
}
179184
}
@@ -331,7 +336,7 @@ export class HTMLGenerator {
331336
}
332337
}
333338

334-
private static generateSideBars(middleContent: HTMLElement, file: ExportFile): { container: HTMLElement, left: HTMLElement, leftScroll: HTMLElement, right: HTMLElement, rightScroll: HTMLElement, center: HTMLElement } {
339+
private static generateSideBars(middleContent: HTMLElement, file: ExportFile, customPageSettings: ICustomPageSettings): { container: HTMLElement, left: HTMLElement, leftScroll: HTMLElement, right: HTMLElement, rightScroll: HTMLElement, center: HTMLElement } {
335340
let docEl = file.document;
336341

337342
/*
@@ -373,12 +378,16 @@ export class HTMLGenerator {
373378

374379
documentContainer.appendChild(middleContent);
375380

376-
const tmpDiv = document.createElement('div');
377-
tmpDiv.innerHTML = WMS_FOOTER;
378-
const footerStyle = document.createElement('style');
379-
footerStyle.innerHTML = WMS_FOOTER_STYLE;
380-
documentContainer.appendChild(footerStyle);
381-
documentContainer.appendChild(tmpDiv.firstChild);
381+
if (customPageSettings?.style) {
382+
const footerStyle = document.createElement('style');
383+
footerStyle.innerHTML = customPageSettings.style;
384+
documentContainer.appendChild(footerStyle);
385+
}
386+
if (customPageSettings?.footer) {
387+
const tmpDiv = document.createElement('div');
388+
tmpDiv.innerHTML = customPageSettings.footer;
389+
documentContainer.appendChild(tmpDiv.firstChild);
390+
}
382391

383392
rightSidebar.classList.add("sidebar");
384393
rightSidebar.appendChild(rightContent);

src/html-generation/wms-footer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export const WMS_FOOTER = `<footer class="footer_d1NW"><div class="contactArea_F3xQ"><div><h2>联系我们</h2><div><p>网站:<a href="https://wms.webinfra.cloud" target="__blank">https://wms.webinfra.cloud</a></p><p>电话:<a href="tel:19537602183">19537602183</a></p><p>地址:上海市嘉定区云谷路399号嘉定新城科创智慧园T2办公楼</p></div></div><div class="qrs_s00F"><div class="qr_gmUh"><div class="qrTitle_TmNk"><span>关注公众号</span><br><span>了解前沿WMS知识</span></div><div style="margin-top:1rem"><img src="img/company_qr.jpg" alt="公众号二维码" style="width:80px;height:80px"></div></div><div class="qr_gmUh"><div class="qrTitle_TmNk"><span>客服微信</span><br><span>只冲WMS产品</span></div><div style="margin-top:1rem"><img src="img/sales_qr.jpg" alt="客服二维码" style="width:80px;height:80px"></div></div></div></div><div class="beian_B2zb"><div><a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener noreferrer" style="color:inherit;text-decoration:none">沪ICP备2023003164号-1</a></div><div style="margin-left:1rem"><span>Copyright © <!-- -->2024<!-- --> 只冲科技, Inc. All rights reserved.</span></div></div></footer>`
2-
export const WMS_FOOTER_STYLE = `.footer_d1NW{background-color:#303846;color:#fff;padding:1rem}.contactArea_F3xQ{align-items:center;color:#fff;display:flex;font-size:1rem;justify-content:center}.contactArea_F3xQ a{color:inherit;font-weight:700}.qrs_s00F{display:flex;flex:0 0 auto}.qr_gmUh{flex:1;min-width:118px;text-align:center}.beian_B2zb,.buttons_c5vH{align-items:center;display:flex}.qrTitle_TmNk{font-size:smaller}.beian_B2zb{color:#ffffff6b;flex-direction:row;font-size:small;justify-content:center;margin-top:2rem}@media screen and (max-width:767px){.contactArea_F3xQ{flex-direction:column}.qrs_s00F{width:100%}.beian_B2zb{display:none}}`
2+
export const WMS_FOOTER_STYLE = `p img {max-height: 12rem;} .footer_d1NW{background-color:#303846;color:#fff;padding:1rem}.contactArea_F3xQ{align-items:center;color:#fff;display:flex;font-size:1rem;justify-content:center}.contactArea_F3xQ a{color:inherit;font-weight:700}.qrs_s00F{display:flex;flex:0 0 auto}.qr_gmUh{flex:1;min-width:118px;text-align:center}.beian_B2zb,.buttons_c5vH{align-items:center;display:flex}.qrTitle_TmNk{font-size:smaller}.beian_B2zb{color:#ffffff6b;flex-direction:row;font-size:small;justify-content:center;margin-top:2rem}@media screen and (max-width:767px){.contactArea_F3xQ{flex-direction:column}.qrs_s00F{width:100%}.beian_B2zb{display:none}}`

src/langs/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@
171171
"settings_skiplargefiles_desc": "Skip files with sizes larger than the threshold. Here 1 MB = 10^6 bytes.",
172172
"settings_skiplargefiles_notset": "(not set)",
173173

174+
"settings_customfooter": "Custom Footer",
175+
"settings_customfooter_desc": "Costom footer html contents.",
176+
177+
"settings_customstyle": "Custom Style",
178+
"settings_customstyle_desc": "Costom style css contents.",
179+
174180
"settings_checkonnectivity": "Check Connectivity",
175181
"settings_checkonnectivity_desc": "Check connectivity.",
176182
"settings_checkonnectivity_button": "Check",

src/langs/zh_cn.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@
170170
"settings_skiplargefiles_desc": "跳过大于某一个阈值的文件。这里 1 MB = 10^6 bytes。",
171171
"settings_skiplargefiles_notset": "(不设置)",
172172

173+
"settings_customfooter": "自定义Footer",
174+
"settings_customfooter_desc": "Html格式的自定义Footer",
175+
176+
"settings_customstyle": "自定义样式",
177+
"settings_customstyle_desc": "自定义Css样式",
178+
173179
"settings_checkonnectivity": "检查可否连接",
174180
"settings_checkonnectivity_desc": "检查可否连接。",
175181
"settings_checkonnectivity_button": "检查",

src/langs/zh_tw.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
"settings_skiplargefiles_desc": "跳過大於某一個閾值的檔案。這裡 1 MB = 10^6 bytes。",
171171
"settings_skiplargefiles_notset": "(不設定)",
172172

173+
"settings_customfooter": "自定义Footer",
174+
"settings_customfooter_desc": "Html格式的自定义Footer",
175+
"settings_customstyle": "自定义样式",
176+
"settings_customstyle_desc": "自定义Css样式",
177+
173178
"settings_checkonnectivity": "檢查可否連線",
174179
"settings_checkonnectivity_desc": "檢查可否連線。",
175180
"settings_checkonnectivity_button": "檢查",

src/settings.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ const DEFAULT_SETTINGS: InvioPluginSettings = {
8080
lang: "auto",
8181
logToDB: false,
8282
skipSizeLargerThan: -1,
83+
customFooter: '',
84+
customStyle: '',
8385
};
8486

8587
export const getDEFAULT_SETTINGS = (): InvioPluginSettings => {
@@ -108,6 +110,8 @@ export const getDEFAULT_SETTINGS = (): InvioPluginSettings => {
108110
lang: "auto",
109111
logToDB: false,
110112
skipSizeLargerThan: -1,
113+
customFooter: '',
114+
customStyle: '',
111115
});
112116
}
113117

@@ -1022,6 +1026,32 @@ export class InvioSettingTab extends PluginSettingTab {
10221026
});
10231027
});
10241028

1029+
new Setting(basicDiv)
1030+
.setName(t("settings_customfooter"))
1031+
.setDesc(t("settings_customfooter_desc"))
1032+
.addTextArea((text) =>
1033+
text
1034+
.setPlaceholder("")
1035+
.setValue(`${this.plugin.settings.customFooter}`)
1036+
.onChange(async (value) => {
1037+
this.plugin.settings.customFooter = value.trim();
1038+
await this.plugin.saveSettings();
1039+
})
1040+
);
1041+
1042+
new Setting(basicDiv)
1043+
.setName(t("settings_customstyle"))
1044+
.setDesc(t("settings_customstyle_desc"))
1045+
.addTextArea((text) =>
1046+
text
1047+
.setPlaceholder("")
1048+
.setValue(`${this.plugin.settings.customStyle}`)
1049+
.onChange(async (value) => {
1050+
this.plugin.settings.customStyle = value.trim();
1051+
await this.plugin.saveSettings();
1052+
})
1053+
);
1054+
10251055
//////////////////////////////////////////////////
10261056
// below for advanced settings
10271057
//////////////////////////////////////////////////

0 commit comments

Comments
 (0)