add support for cover image and title icon

This commit is contained in:
Jiaxin Peng
2023-08-10 22:04:57 +01:00
parent 9be679f456
commit 679e7ec4f1
7 changed files with 47 additions and 10 deletions

View File

@@ -27,6 +27,10 @@
- password - password
- icon - icon
在最新的0.0.6版本,我还增加了以下内容:
- titleicon 标题的emoji图标,暂时只能支持emoji
- coverurl 封面图片的url url可以是任何一种图片的url 例如jpgpngsvg等等。
**如果你是直接复制的NotionNext的模板这些内容应该已经有了。我在原作者的基础之上对本插件的内容进行了更改所以你只需要保证你的数据库有如上内容并且所有的字母都是小写** **如果你是直接复制的NotionNext的模板这些内容应该已经有了。我在原作者的基础之上对本插件的内容进行了更改所以你只需要保证你的数据库有如上内容并且所有的字母都是小写**
@@ -50,6 +54,11 @@
# for example, if you donot want to set password, you can delete password: "1234" or set it to password: "" # for example, if you donot want to set password, you can delete password: "1234" or set it to password: ""
# 我已经在插件中设置了默认值,如果有不需要的选项,可以直接删除。 # 我已经在插件中设置了默认值,如果有不需要的选项,可以直接删除。
# 例如你不需要密码选项你可以将password: "1234"删除,或者将它设置为空。 # 例如你不需要密码选项你可以将password: "1234"删除,或者将它设置为空。
# !!!!!!!!!!!!
# 现在阶段一定不要修改表头的名字, please do not change the name of the header in YAML front matter
# !!!!!!!!!!!!
titleicon: 📎 # emoji icon, default is 📜, 默认是📜
coverurl: https://img.jxpeng.dev/2023/08/843e27a210847f05a0f7cfb121fec100.jpg # default is empty 默认是空
type: Post # Post or Page, default is Post 默认是Post type: Post # Post or Page, default is Post 默认是Post
slug: test # slug for url, default is empty 默认是空 slug: test # slug for url, default is empty 默认是空
stats: Draft # Draft, Invisible, Published, default is Draft 默认是Draft stats: Draft # Draft, Invisible, Published, default is Draft 默认是Draft

View File

@@ -28,6 +28,10 @@ Before installing the plugin, you must have set up the following:
- password - password
- icon - icon
In version 0.0.6, I also add the following contents:
- titleicon: the unique icon for each post, it can only support emoji currently.
- cover url: the cover image for each post, it should be end with a type of image, such as .jpg, .png, .gif, etc.
**If you've directly copied the NotionNext template, these contents should already exist. I've made changes to this plugin based on the original author's work. All you need to ensure is that your database has the above content, and every letter is in lowercase!!!** **If you've directly copied the NotionNext template, these contents should already exist. I've made changes to this plugin based on the original author's work. All you need to ensure is that your database has the above content, and every letter is in lowercase!!!**
**⚠️⚠️⚠️: All headers are in lowercase!!! The order doesn't matter!** **⚠️⚠️⚠️: All headers are in lowercase!!! The order doesn't matter!**
@@ -50,6 +54,11 @@ If you don't want to use the template, you can also directly create a new file i
# for example, if you donot want to set password, you can delete password: "1234" or set it to password: "" # for example, if you donot want to set password, you can delete password: "1234" or set it to password: ""
# 我已经在插件中设置了默认值,如果有不需要的选项,可以直接删除。 # 我已经在插件中设置了默认值,如果有不需要的选项,可以直接删除。
# 例如你不需要密码选项你可以将password: "1234"删除,或者将它设置为空。 # 例如你不需要密码选项你可以将password: "1234"删除,或者将它设置为空。
# !!!!!!!!!!!!
# 现在阶段一定不要修改表头的名字, please do not change the name of the header in YAML front matter
# !!!!!!!!!!!!
titleicon: 📎 # emoji icon, default is 📜, 默认是📜
coverurl: https://img.jxpeng.dev/2023/08/843e27a210847f05a0f7cfb121fec100.jpg # default is empty 默认是空
type: Post # Post or Page, default is Post 默认是Post type: Post # Post or Page, default is Post 默认是Post
slug: test # slug for url, default is empty 默认是空 slug: test # slug for url, default is empty 默认是空
stats: Draft # Draft, Invisible, Published, default is Draft 默认是Draft stats: Draft # Draft, Invisible, Published, default is Draft 默认是Draft

View File

@@ -28,17 +28,25 @@ export class Upload2Notion {
// 因为需要解析notion的block进行对比非常的麻烦 // 因为需要解析notion的block进行对比非常的麻烦
// 暂时就直接删除新建一个page // 暂时就直接删除新建一个page
async updatePage(notionID:string, title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, paword:string, favicon:string, datetime:string, childArr:any) { async updatePage(notionID:string, title:string, allowTags:boolean, emoji:string, cover:string, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, paword:string, favicon:string, datetime:string, childArr:any) {
await this.deletePage(notionID) await this.deletePage(notionID)
const res = await this.createPage(title, allowTags, tags, type, slug, stats, category, summary, paword, favicon, datetime, childArr) const res = await this.createPage(title, allowTags, emoji,cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, childArr)
return res return res
} }
async createPage(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, pawrod:string, favicon:string, datetime:string, childArr: any) { async createPage(title:string, allowTags:boolean, emoji:string, cover:string, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, pawrod:string, favicon:string, datetime:string, childArr: any) {
const bodyString:any = { const bodyString:any = {
parent: { parent: {
database_id: this.app.settings.databaseID database_id: this.app.settings.databaseID
}, },
icon: {
emoji: emoji || '📜'
},
cover: {
external: {
url: cover || ''
}
},
properties: { properties: {
title: { title: {
title: [ title: [
@@ -141,7 +149,7 @@ export class Upload2Notion {
} }
} }
async syncMarkdownToNotion(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, paword:string, favicon:string, datetime:string, markdown: string, nowFile: TFile, app:App, settings:any): Promise<any> { async syncMarkdownToNotion(title:string, allowTags:boolean, emoji:string, cover:string, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, paword:string, favicon:string, datetime:string, markdown: string, nowFile: TFile, app:App, settings:any): Promise<any> {
let res:any let res:any
const yamlObj:any = yamlFrontMatter.loadFront(markdown); const yamlObj:any = yamlFrontMatter.loadFront(markdown);
const __content = yamlObj.__content const __content = yamlObj.__content
@@ -150,9 +158,9 @@ export class Upload2Notion {
const notionID = frontmasster ? frontmasster.notionID : null const notionID = frontmasster ? frontmasster.notionID : null
if(notionID){ if(notionID){
res = await this.updatePage(notionID, title, allowTags, tags, type, slug, stats, category, summary, paword, favicon, datetime, file2Block); res = await this.updatePage(notionID, title, allowTags, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, file2Block);
} else { } else {
res = await this.createPage(title, allowTags, tags, type, slug, stats, category, summary, paword, favicon, datetime, file2Block); res = await this.createPage(title, allowTags, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, file2Block);
} }
if (res.status === 200) { if (res.status === 200) {
await this.updateYamlInfo(markdown, nowFile, res, app, settings) await this.updateYamlInfo(markdown, nowFile, res, app, settings)

10
main.ts
View File

@@ -80,12 +80,12 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
); );
return; return;
} }
const { markDownData, nowFile, tags, type, slug, stats, category, summary, paword, favicon, datetime } =await this.getNowFileMarkdownContent(this.app); const { markDownData, nowFile, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime } =await this.getNowFileMarkdownContent(this.app);
if (markDownData) { if (markDownData) {
const { basename } = nowFile; const { basename } = nowFile;
const upload = new Upload2Notion(this); const upload = new Upload2Notion(this);
const res = await upload.syncMarkdownToNotion(basename, allowTags, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app, this.settings) const res = await upload.syncMarkdownToNotion(basename, allowTags, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app, this.settings)
if(res.status === 200){ if(res.status === 200){
new Notice(`${langConfig["sync-success"]}${basename}`) new Notice(`${langConfig["sync-success"]}${basename}`)
}else { }else {
@@ -97,6 +97,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
async getNowFileMarkdownContent(app: App) { async getNowFileMarkdownContent(app: App) {
const nowFile = app.workspace.getActiveFile(); const nowFile = app.workspace.getActiveFile();
const { allowTags } = this.settings; const { allowTags } = this.settings;
let emoji = ''
let cover = ''
let tags = [] let tags = []
let type = '' let type = ''
let slug = '' let slug = ''
@@ -110,6 +112,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
const FileCache = app.metadataCache.getFileCache(nowFile) const FileCache = app.metadataCache.getFileCache(nowFile)
try { try {
if(allowTags) { if(allowTags) {
emoji = FileCache.frontmatter.titleicon;
cover = FileCache.frontmatter.coverurl;
tags = FileCache.frontmatter.tags; tags = FileCache.frontmatter.tags;
type = FileCache.frontmatter.type; type = FileCache.frontmatter.type;
slug = FileCache.frontmatter.slug; slug = FileCache.frontmatter.slug;
@@ -128,6 +132,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
return { return {
markDownData, markDownData,
nowFile, nowFile,
emoji,
cover,
tags, tags,
type, type,
slug, slug,

View File

@@ -1,7 +1,7 @@
{ {
"id": "share-to-notionnext", "id": "share-to-notionnext",
"name": "Share to NotionNext", "name": "Share to NotionNext",
"version": "0.0.5", "version": "0.0.6",
"minAppVersion": "0.0.1", "minAppVersion": "0.0.1",
"description": "This is a plugin for Obsidian. This plugin shares obsidian md file to notion with notion api for NotionNext web deploy.", "description": "This is a plugin for Obsidian. This plugin shares obsidian md file to notion with notion api for NotionNext web deploy.",
"author": "jxpeng98", "author": "jxpeng98",

View File

@@ -4,6 +4,11 @@
# for example, if you donot want to set password, you can delete password: "1234" or set it to password: "" # for example, if you donot want to set password, you can delete password: "1234" or set it to password: ""
# 我已经在插件中设置了默认值,如果有不需要的选项,可以直接删除。 # 我已经在插件中设置了默认值,如果有不需要的选项,可以直接删除。
# 例如你不需要密码选项你可以将password: "1234"删除,或者将它设置为空。 # 例如你不需要密码选项你可以将password: "1234"删除,或者将它设置为空。
# !!!!!!!!!!!!
# 现在阶段一定不要修改表头的名字, please do not change the name of the header in YAML front matter
# !!!!!!!!!!!!
titleicon: 📎 # default is 📜, 默认是📜
coverurl: https://img.jxpeng.dev/2023/08/843e27a210847f05a0f7cfb121fec100.jpg # default is empty 默认是空
type: Post # Post or Page, default is Post 默认是Post type: Post # Post or Page, default is Post 默认是Post
slug: test # slug for url, default is empty 默认是空 slug: test # slug for url, default is empty 默认是空
stats: Draft # Draft, Invisible, Published, default is Draft 默认是Draft stats: Draft # Draft, Invisible, Published, default is Draft 默认是Draft

View File

@@ -1,6 +1,6 @@
{ {
"name": "share-to-notionnext", "name": "share-to-notionnext",
"version": "0.0.5", "version": "0.0.6",
"type": "module", "type": "module",
"description": "This is a plugin for Obsidian. This plugin share obsidian md file to notion with notion api for NotionNext web deploy.", "description": "This is a plugin for Obsidian. This plugin share obsidian md file to notion with notion api for NotionNext web deploy.",
"main": "main.js", "main": "main.js",