Skip to content

Commit

Permalink
support multiple languages
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwei committed Jan 1, 2025
1 parent 511276d commit 04e0562
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "mdfriday",
"name": "Friday",
"version": "0.2.0",
"version": "0.2.1",
"minAppVersion": "0.15.0",
"description": "Notes to Website. Friday helps you turn Markdown documents into websites in minutes.",
"author": "sunwei",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-friday-plugin",
"version": "0.2.0",
"version": "0.2.1",
"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": {
Expand Down
10 changes: 8 additions & 2 deletions src/fileinfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {App, Notice, TFolder} from "obsidian";
import {FM_CONTENT, FM_CONTENT_EMPTY, FM_FRIDAY_PLUGIN, FM_SITE_ID, FM_THEME} from "./frontmatter";
import {FM_CONTENT, FM_CONTENT_EMPTY, FM_FRIDAY_PLUGIN, FM_MENU, FM_SITE_ID, FM_THEME} from "./frontmatter";
import * as path from "path";
import * as yaml from "js-yaml";
import {IsLanguageSupported, IsRtlLanguage} from "./language";
Expand All @@ -10,6 +10,7 @@ export class FileInfo {
frontMatter: Record<string, any> | null;
content: string;
languages: string[] = [];
menus: string[] = [];

isContentFolderExists: boolean;
isReadyForBuild: boolean
Expand Down Expand Up @@ -47,6 +48,7 @@ export class FileInfo {
this.content = this.extractContentWithoutFrontmatter(fileContent, this.frontMatter); // 存储去掉 frontmatter 的内容

this.languages = this.detectLanguageFolders();
this.menus = this.getMenus();

callback(this); // 通知外部异步操作已完成
} else {
Expand Down Expand Up @@ -114,6 +116,10 @@ export class FileInfo {
return this.frontMatter?.[FM_CONTENT] ?? ''
}

getMenus(): string[] {
return this.frontMatter?.[FM_MENU] ?? []
}

getSiteId(): string {
return this.frontMatter?.[FM_SITE_ID] ?? '0';
}
Expand All @@ -127,7 +133,7 @@ export class FileInfo {
}

getParams(): string {
const excludeKeys = [FM_FRIDAY_PLUGIN, FM_SITE_ID, FM_CONTENT, FM_THEME];
const excludeKeys = [FM_FRIDAY_PLUGIN, FM_SITE_ID, FM_CONTENT, FM_THEME, FM_MENU];

const paramsArray = [];
for (const key in this.frontMatter) {
Expand Down
1 change: 1 addition & 0 deletions src/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const FM_CONTENT = 'content';
export const FM_CONTENT_EMPTY = 'empty';
export const FM_THEME = 'theme';
export const FM_DEFAULT_THEME = 'github.com/mdfriday/theme-long-teng';
export const FM_MENU = 'menu';

const basicFrontMatter = [
'---',
Expand Down
9 changes: 5 additions & 4 deletions src/hugoverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export class Hugoverse {
}

projectDirPath(filepath: string): string {
const projDirPath = path.join(path.dirname(filepath), "MDFriday");

return projDirPath;
return path.dirname(filepath)
}

async loadManifestConfig() {
Expand Down Expand Up @@ -178,7 +176,7 @@ export class Hugoverse {

// 等待所有文件的处理完成
await Promise.all(filePromises);
await new Promise(resolve => setTimeout(resolve, 2000)); // 延迟 2 秒
await new Promise(resolve => setTimeout(resolve, 3000)); // 延迟 2 秒

} else {
console.warn(`Path "${this.plugin.fileInfo.getContentFolder()}" is not a folder.`);
Expand Down Expand Up @@ -273,6 +271,9 @@ export class Hugoverse {
this.plugin.fileInfo.languages.forEach((lang, index) => {
body.append(`languages.${index}`, lang);
});
this.plugin.fileInfo.menus.forEach((menu, index) => {
body.append(`menus.${index}`, menu);
})

// 将 FormData 转换为 ArrayBuffer
const boundary = "----WebKitFormBoundary" + Math.random().toString(36).substring(2, 9);
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"0.1.6": "0.15.0",
"0.1.7": "0.15.0",
"0.1.8": "0.15.0",
"0.2.0": "0.15.0"
"0.2.0": "0.15.0",
"0.2.1": "0.15.0"
}

0 comments on commit 04e0562

Please sign in to comment.