mirror of
https://github.com/omnivore-app/logseq-omnivore.git
synced 2026-05-21 09:10:35 +00:00
feat: allow defining custom title of heading block in the settings or leave blank to not create one (#144)
* feat: allow defining custom title of heading block in the settings or leave blank to not create one * remove some debugging logs
This commit is contained in:
+27
-18
@@ -126,22 +126,30 @@ const getOmnivorePage = async (pageName: string): Promise<PageEntity> => {
|
||||
return newOmnivorePage
|
||||
}
|
||||
|
||||
const getOmnivoreBlock = async (
|
||||
const getOmnivoreBlockIdentity = async (
|
||||
pageName: string,
|
||||
title: string
|
||||
): Promise<BlockEntity> => {
|
||||
): Promise<string> => {
|
||||
const page = await getOmnivorePage(pageName)
|
||||
const targetBlock = await getBlockByContent(pageName, page.uuid, title)
|
||||
if (targetBlock) {
|
||||
return targetBlock
|
||||
}
|
||||
const newTargetBlock = await logseq.Editor.appendBlockInPage(page.uuid, title)
|
||||
if (!newTargetBlock) {
|
||||
await logseq.UI.showMsg(t('Failed to create Omnivore block'), 'error')
|
||||
throw new Error('Failed to create Omnivore block')
|
||||
if (!title) {
|
||||
// return the page uuid if no title is provided
|
||||
return page.uuid
|
||||
}
|
||||
|
||||
return newTargetBlock
|
||||
const targetBlock = await getBlockByContent(pageName, page.uuid, title)
|
||||
if (targetBlock) {
|
||||
return targetBlock.uuid
|
||||
}
|
||||
const newTargetBlock = await logseq.Editor.prependBlockInPage(
|
||||
page.uuid,
|
||||
title
|
||||
)
|
||||
if (!newTargetBlock) {
|
||||
await logseq.UI.showMsg(t('Failed to create Omnivore block'), 'error')
|
||||
throw new Error('Failed to create block')
|
||||
}
|
||||
|
||||
return newTargetBlock.uuid
|
||||
}
|
||||
|
||||
const fetchOmnivore = async (inBackground = false) => {
|
||||
@@ -158,6 +166,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
loading,
|
||||
endpoint,
|
||||
isSinglePage,
|
||||
headingBlockTitle,
|
||||
} = logseq.settings as Settings
|
||||
// prevent multiple fetches
|
||||
if (loading) {
|
||||
@@ -193,7 +202,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
return
|
||||
}
|
||||
|
||||
const blockTitle = t('## 🔖 Articles')
|
||||
const blockTitle = t(headingBlockTitle)
|
||||
const fetchingTitle = t('🚀 Fetching articles ...')
|
||||
const highlightTitle = t('### Highlights')
|
||||
|
||||
@@ -214,7 +223,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
if (isSinglePage) {
|
||||
// create a single page for all articles
|
||||
pageName = pageNameTemplate
|
||||
targetBlockId = (await getOmnivoreBlock(pageName, blockTitle)).uuid
|
||||
targetBlockId = await getOmnivoreBlockIdentity(pageName, blockTitle)
|
||||
!inBackground && logseq.App.pushState('page', { name: pageName })
|
||||
}
|
||||
|
||||
@@ -245,7 +254,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
pageName = replaceIllegalChars(
|
||||
renderPageName(article, pageNameTemplate, preferredDateFormat)
|
||||
)
|
||||
targetBlockId = (await getOmnivoreBlock(pageName, blockTitle)).uuid
|
||||
targetBlockId = await getOmnivoreBlockIdentity(pageName, blockTitle)
|
||||
}
|
||||
const articleBatch = articleBatchMap.get(targetBlockId) || []
|
||||
// render article content
|
||||
@@ -324,7 +333,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
// check if highlight title block exists
|
||||
const existingHighlightTitleBlock = await getBlockByContent(
|
||||
pageName,
|
||||
existingArticleBlock.uuid,
|
||||
parentBlockId,
|
||||
highlightTitleBlock.content
|
||||
)
|
||||
if (existingHighlightTitleBlock) {
|
||||
@@ -394,7 +403,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
}
|
||||
}
|
||||
|
||||
for await (const [targetBlockId, articleBatch] of articleBatchMap) {
|
||||
for (const [targetBlockId, articleBatch] of articleBatchMap) {
|
||||
await logseq.Editor.insertBatchBlock(targetBlockId, articleBatch, {
|
||||
before: true,
|
||||
sibling: false,
|
||||
@@ -414,14 +423,14 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
parseDateTime(syncAt).toISO(),
|
||||
endpoint
|
||||
)
|
||||
for await (const deletedArticle of deletedArticles) {
|
||||
for (const deletedArticle of deletedArticles) {
|
||||
if (!isSinglePage) {
|
||||
pageName = renderPageName(
|
||||
deletedArticle,
|
||||
pageNameTemplate,
|
||||
preferredDateFormat
|
||||
)
|
||||
targetBlockId = (await getOmnivoreBlock(pageName, blockTitle)).uuid
|
||||
targetBlockId = await getOmnivoreBlockIdentity(pageName, blockTitle)
|
||||
|
||||
// delete page if article is synced to a separate page and page is not a journal
|
||||
const existingPage = await logseq.Editor.getPage(pageName)
|
||||
|
||||
@@ -30,6 +30,7 @@ export interface Settings {
|
||||
endpoint: string
|
||||
isSinglePage: boolean
|
||||
version: string
|
||||
headingBlockTitle: string
|
||||
}
|
||||
|
||||
export const getQueryFromFilter = (
|
||||
@@ -174,6 +175,17 @@ export const settingsSchema = async (): Promise<SettingSchemaDesc[]> => [
|
||||
description: t('This page will be created if it does not exist.'),
|
||||
default: 'Omnivore',
|
||||
},
|
||||
{
|
||||
key: 'headingBlockTitle',
|
||||
type: 'string',
|
||||
title: t(
|
||||
'Enter the title of the heading block to place synced articles under'
|
||||
),
|
||||
description: t(
|
||||
'This heading block will be created if it does not exist. Default is "## 🔖 Articles". Leave blank to not create a heading block.'
|
||||
),
|
||||
default: '## 🔖 Articles',
|
||||
},
|
||||
{
|
||||
key: 'endpoint',
|
||||
type: 'string',
|
||||
|
||||
Reference in New Issue
Block a user