diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 3931abe..578cc4f 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -11,7 +11,7 @@ if you want to view the source, please visit the github repository of this plugi ` const prod = process.argv[2] === 'production' -const outputFile = prod ? 'main.js' : '/Users/sunwei/Documents/Obsidian Vault/.obsidian/plugins/obsidian-friday-plugin/main.js'; +const outputFile = prod ? 'main.js' : '/Users/sunwei/Documents/Obsidian/.obsidian/plugins/mdfriday/main.js'; esbuild .build({ diff --git a/manifest.json b/manifest.json index 943781f..66942b9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "mdfriday", "name": "Friday", - "version": "0.1.8", + "version": "0.2.0", "minAppVersion": "0.15.0", "description": "Notes to Website. Friday helps you turn Markdown documents into websites in minutes.", "author": "sunwei", diff --git a/package.json b/package.json index 7efa66d..6def945 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-friday-plugin", - "version": "0.1.8", + "version": "0.2.0", "description": "Friday is an Obsidian plugin that empowers users to focus on content creation by writing Markdown files, while we handle the distribution. From creating websites to content deployment, Friday serves as a creative output assistant, helping users turn their work into publishable sites with ease.", "main": "main.js", "scripts": { diff --git a/src/hugoverse.ts b/src/hugoverse.ts index d1be097..fd52721 100644 --- a/src/hugoverse.ts +++ b/src/hugoverse.ts @@ -193,7 +193,8 @@ export class Hugoverse { } callback(100); // 预览完成,进度达到100% - const modal = new WebPreviewModal(this.app, preUrl); // 创建一个 WebPreviewModal 实例 + const newUrl = preUrl.replace("app.mdfriday.com", "netlify.app"); + const modal = new WebPreviewModal(this.app, newUrl); // 创建一个 WebPreviewModal 实例 modal.open(); return preUrl; @@ -213,6 +214,9 @@ export class Hugoverse { // 创建 FormData 实例并添加 siteId 字段 let body = new FormData(); body.append("site", `${siteId}`); + body.append("domain", this.plugin.settings.rootDomain); + body.append("host_name", "Netlify"); + body.append("host_token", this.plugin.settings.netlifyToken); // 将 FormData 转换为 ArrayBuffer const boundary = "----WebKitFormBoundary" + Math.random().toString(36).substring(2, 9); diff --git a/src/main.ts b/src/main.ts index 8671fa8..20074f5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,18 +9,25 @@ interface FridaySettings { username: string; password: string; userToken: string; + + rootDomain: string + netlifyToken: string } const DEFAULT_SETTINGS: FridaySettings = { username: '', password: '', userToken: '', + rootDomain: '', + netlifyToken: '' } export const FRIDAY_ICON = 'dice-5'; export const API_URL_DEV = 'http://127.0.0.1:1314'; export const API_URL_PRO = 'https://mdfriday.sunwei.xyz'; +const FRIDAY_ROOT_FOLDER = 'MDFriday'; + export default class FridayPlugin extends Plugin { settings: FridaySettings; statusBar: HTMLElement @@ -75,12 +82,10 @@ export default class FridayPlugin extends Plugin { } async newNote(folder?: TFolder) { - const targetFolder = folder - ? folder - : this.app.fileManager.getNewFileParent(this.app.workspace.getActiveFile()?.path || ''); + await this.ensureRootFolderExists(); try { - const fNote: TFile = await this.createUniqueMarkdownFile(targetFolder.path, 'Untitled Friday Site'); + const fNote: TFile = await this.createUniqueMarkdownFile(FRIDAY_ROOT_FOLDER, 'Untitled Friday Site'); await this.app.vault.modify(fNote, getDefaultFrontMatter()); await this.app.workspace.getLeaf().openFile(fNote); @@ -90,6 +95,12 @@ export default class FridayPlugin extends Plugin { } } + async ensureRootFolderExists() { + if (!(await this.app.vault.adapter.exists(FRIDAY_ROOT_FOLDER))) { + await this.app.vault.createFolder(FRIDAY_ROOT_FOLDER); + } + } + async createUniqueMarkdownFile(targetFolder: string, baseFileName: string): Promise { let fileIndex = 0; let newFile: TFile | null = null; @@ -133,12 +144,12 @@ class FridaySettingTab extends PluginSettingTab { containerEl.empty(); - const { username, password, userToken } = this.plugin.settings; + const {username, password, userToken} = this.plugin.settings; if (userToken) { // 用户已登录的界面 - containerEl.createEl("h2", { text: "Welcome Back!" }); - containerEl.createEl("p", { text: `Logged in as: ${username}` }); + containerEl.createEl("h2", {text: "Welcome Back!"}); + containerEl.createEl("p", {text: `Logged in as: ${username}`}); new Setting(containerEl) .addButton((button) => @@ -152,8 +163,8 @@ class FridaySettingTab extends PluginSettingTab { ); } else { // 用户未登录的界面 - containerEl.createEl("h2", { text: "Welcome!" }); - containerEl.createEl("p", { text: "Please enter your credentials." }); + containerEl.createEl("h2", {text: "Welcome!"}); + containerEl.createEl("p", {text: "Please enter your credentials."}); // Email 输入框 new Setting(containerEl) @@ -195,15 +206,42 @@ class FridaySettingTab extends PluginSettingTab { this.display(); // 刷新界面 }) ).addButton((button) => - button - .setButtonText("Login") - .setCta() - .onClick(async () => { - await this.plugin.user.login(); // 处理登录逻辑 - this.display(); // 刷新界面 - }) + button + .setButtonText("Login") + .setCta() + .onClick(async () => { + await this.plugin.user.login(); // 处理登录逻辑 + this.display(); // 刷新界面 + }) ); } + containerEl.createEl("h2", {text: "Deployment"}); + new Setting(containerEl) + .setName("Root Domain") + .setDesc("Set your custom root domain (e.g., mdfriday.com). This will be used for generated links.") + .addText(text => + text + .setPlaceholder("Enter your root domain") + .setValue(this.plugin.settings.rootDomain || "") + .onChange(async (value) => { + this.plugin.settings.rootDomain = value; + await this.plugin.saveSettings(); + }) + ); + + new Setting(containerEl) + .setName("Netlify Token") + .setDesc("Set your Netlify personal access token here.") + .addText(text => + text + .setPlaceholder("Enter your Netlify Token") + .setValue(this.plugin.settings.netlifyToken || "") + .onChange(async (value) => { + this.plugin.settings.netlifyToken = value; + await this.plugin.saveSettings(); + }) + ); + } } diff --git a/src/preview.ts b/src/preview.ts index 3ac45d0..1387f14 100644 --- a/src/preview.ts +++ b/src/preview.ts @@ -14,15 +14,46 @@ export class WebPreviewModal extends Modal { // Apply CSS class to modal modalEl.classList.add('friday-preview-modal'); + this.showLoadingMessage() + setTimeout(() => { + this.loadIframe(); + }, 1000); + } + + showLoadingMessage() { + const { contentEl } = this; + contentEl.empty(); // 清空内容 + + const loadingMessage = document.createElement('p'); + loadingMessage.textContent = "Loading..."; + loadingMessage.classList.add('friday-preview-loading'); + contentEl.appendChild(loadingMessage); + } + + loadIframe() { + const { contentEl } = this; + // Create and style the iframe with a CSS class const iframe = document.createElement('iframe'); iframe.src = this.url; iframe.classList.add('friday-preview-iframe'); + iframe.onload = () => { + setTimeout(() => { + this.onIframeLoaded(contentEl, iframe); + }, 500); + }; // Insert the iframe into the modal content contentEl.appendChild(iframe); } + onIframeLoaded(contentEl: HTMLElement, iframe: HTMLIFrameElement) { + // iframe 加载完成后,隐藏加载提示 + const loadingMessage = contentEl.querySelector('.friday-preview-loading'); + if (loadingMessage) { + loadingMessage.remove(); // 移除加载提示 + } + } onClose() { const {contentEl} = this; diff --git a/styles.css b/styles.css index d74b453..16171ca 100644 --- a/styles.css +++ b/styles.css @@ -17,3 +17,11 @@ border: none; background-color: white; } + +.friday-preview-loading { + text-align: center; + margin-top: 20px; + font-size: 18px; + color: black; + height: 100%; +} diff --git a/versions.json b/versions.json index 36aa1bb..ad84754 100644 --- a/versions.json +++ b/versions.json @@ -2,5 +2,6 @@ "0.1.5": "0.15.0", "0.1.6": "0.15.0", "0.1.7": "0.15.0", - "0.1.8": "0.15.0" + "0.1.8": "0.15.0", + "0.2.0": "0.15.0" } \ No newline at end of file