mirror of
https://github.com/omnivore-app/logseq-omnivore.git
synced 2026-05-21 09:10:35 +00:00
fix: importing article {{{ content }}} stops at first section (#154)
* fix: sync article content into another block if turned on in the settings * add localization for zh-CN * fix: add Japanese localization
This commit is contained in:
+1
-1
@@ -51,7 +51,7 @@ export interface Article {
|
||||
updatedAt: string
|
||||
savedAt: string
|
||||
pageType: PageType
|
||||
content: string
|
||||
content?: string
|
||||
publishedAt?: string
|
||||
readAt?: string
|
||||
readingProgressPercent: number
|
||||
|
||||
+66
-22
@@ -22,7 +22,7 @@ import {
|
||||
} from './settings'
|
||||
import {
|
||||
preParseTemplate,
|
||||
renderArticleContent,
|
||||
renderArticle,
|
||||
renderHighlightContent,
|
||||
renderPageName,
|
||||
} from './settings/template'
|
||||
@@ -167,6 +167,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
endpoint,
|
||||
isSinglePage,
|
||||
headingBlockTitle,
|
||||
syncContent,
|
||||
} = logseq.settings as Settings
|
||||
// prevent multiple fetches
|
||||
if (loading) {
|
||||
@@ -205,6 +206,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
const blockTitle = t(headingBlockTitle)
|
||||
const fetchingTitle = t('🚀 Fetching articles ...')
|
||||
const highlightTitle = t('### Highlights')
|
||||
const contentTitle = t('### Content')
|
||||
|
||||
const userConfigs = await logseq.App.getUserConfigs()
|
||||
const preferredDateFormat: string = userConfigs.preferredDateFormat
|
||||
@@ -243,11 +245,11 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
size,
|
||||
parseDateTime(syncAt).toISO(),
|
||||
getQueryFromFilter(filter, customQuery),
|
||||
true,
|
||||
syncContent,
|
||||
'highlightedMarkdown',
|
||||
endpoint
|
||||
)
|
||||
const articleBatchMap: Map<string, IBatchBlock[]> = new Map()
|
||||
const articleBatchBlockMap: Map<string, IBatchBlock[]> = new Map()
|
||||
for (const article of articles) {
|
||||
if (!isSinglePage) {
|
||||
// create a new page for each article
|
||||
@@ -256,13 +258,23 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
)
|
||||
targetBlockId = await getOmnivoreBlockIdentity(pageName, blockTitle)
|
||||
}
|
||||
const articleBatch = articleBatchMap.get(targetBlockId) || []
|
||||
// render article content
|
||||
const articleContent = renderArticleContent(
|
||||
const articleBatchBlock = articleBatchBlockMap.get(targetBlockId) || []
|
||||
// render article
|
||||
const renderedArticle = renderArticle(
|
||||
articleTemplate,
|
||||
article,
|
||||
preferredDateFormat
|
||||
)
|
||||
// create original content title block
|
||||
const contentBlock: IBatchBlock = {
|
||||
content: contentTitle,
|
||||
children: [
|
||||
{
|
||||
// escape # to prevent creating subpages
|
||||
content: article.content?.replaceAll('#', '\\#') || '',
|
||||
},
|
||||
],
|
||||
}
|
||||
// filter out notes and redactions
|
||||
const highlights = article.highlights?.filter(
|
||||
(h) => h.type === HighlightType.Highlight
|
||||
@@ -303,7 +315,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
}) || []
|
||||
|
||||
// create highlight title block
|
||||
const highlightTitleBlock: IBatchBlock = {
|
||||
const highlightBlock: IBatchBlock = {
|
||||
content: highlightTitle,
|
||||
children: highlightBatch,
|
||||
}
|
||||
@@ -315,7 +327,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
)
|
||||
if (existingArticleBlock) {
|
||||
const existingArticleProperties = existingArticleBlock.properties
|
||||
const newArticleProperties = parseBlockProperties(articleContent)
|
||||
const newArticleProperties = parseBlockProperties(renderedArticle)
|
||||
// update the existing article block if any of the properties have changed
|
||||
if (
|
||||
isBlockPropertiesChanged(
|
||||
@@ -325,22 +337,43 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
) {
|
||||
await logseq.Editor.updateBlock(
|
||||
existingArticleBlock.uuid,
|
||||
articleContent
|
||||
renderedArticle
|
||||
)
|
||||
}
|
||||
if (syncContent) {
|
||||
// delete existing content block
|
||||
const existingContentBlock = await getBlockByContent(
|
||||
pageName,
|
||||
existingArticleBlock.uuid,
|
||||
contentTitle
|
||||
)
|
||||
if (existingContentBlock) {
|
||||
await logseq.Editor.removeBlock(existingContentBlock.uuid)
|
||||
}
|
||||
|
||||
// append new content block
|
||||
await logseq.Editor.insertBatchBlock(
|
||||
existingArticleBlock.uuid,
|
||||
contentBlock,
|
||||
{
|
||||
sibling: false,
|
||||
before: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
if (highlightBatch.length > 0) {
|
||||
let parentBlockId = existingArticleBlock.uuid
|
||||
// check if highlight title block exists
|
||||
const existingHighlightTitleBlock = await getBlockByContent(
|
||||
const existingHighlightBlock = await getBlockByContent(
|
||||
pageName,
|
||||
parentBlockId,
|
||||
highlightTitleBlock.content
|
||||
highlightBlock.content
|
||||
)
|
||||
if (existingHighlightTitleBlock) {
|
||||
parentBlockId = existingHighlightTitleBlock.uuid
|
||||
if (existingHighlightBlock) {
|
||||
parentBlockId = existingHighlightBlock.uuid
|
||||
} else {
|
||||
// append new highlight title block
|
||||
const newHighlightTitleBlock = await logseq.Editor.insertBlock(
|
||||
const newHighlightBlock = await logseq.Editor.insertBlock(
|
||||
existingArticleBlock.uuid,
|
||||
highlightTitle,
|
||||
{
|
||||
@@ -348,7 +381,7 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
before: true,
|
||||
}
|
||||
)
|
||||
if (newHighlightTitleBlock) {
|
||||
if (newHighlightBlock) {
|
||||
const existingArticleBlockWithChildren =
|
||||
await logseq.Editor.getBlock(existingArticleBlock.uuid, {
|
||||
includeChildren: true,
|
||||
@@ -360,13 +393,13 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
for (const highlight of existingHighlightBlocks) {
|
||||
await logseq.Editor.moveBlock(
|
||||
highlight.uuid,
|
||||
newHighlightTitleBlock.uuid,
|
||||
newHighlightBlock.uuid,
|
||||
{
|
||||
children: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
parentBlockId = newHighlightTitleBlock.uuid
|
||||
parentBlockId = newHighlightBlock.uuid
|
||||
}
|
||||
}
|
||||
// append new highlights to existing article block
|
||||
@@ -394,16 +427,27 @@ const fetchOmnivore = async (inBackground = false) => {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const children = []
|
||||
|
||||
// add content block if sync content is selected
|
||||
syncContent && children.push(contentBlock)
|
||||
|
||||
// add highlight title block if there are highlights
|
||||
highlightBatch.length > 0 && children.push(highlightBlock)
|
||||
|
||||
// append new article block
|
||||
articleBatch.unshift({
|
||||
content: articleContent,
|
||||
children: highlightBatch.length > 0 ? [highlightTitleBlock] : [], // add highlight title block if there are highlights
|
||||
articleBatchBlock.unshift({
|
||||
content: renderedArticle,
|
||||
children,
|
||||
properties: {
|
||||
id: article.id,
|
||||
},
|
||||
})
|
||||
articleBatchMap.set(targetBlockId, articleBatch)
|
||||
articleBatchBlockMap.set(targetBlockId, articleBatchBlock)
|
||||
}
|
||||
}
|
||||
|
||||
for (const [targetBlockId, articleBatch] of articleBatchMap) {
|
||||
for (const [targetBlockId, articleBatch] of articleBatchBlockMap) {
|
||||
await logseq.Editor.insertBatchBlock(targetBlockId, articleBatch, {
|
||||
before: true,
|
||||
sibling: false,
|
||||
|
||||
@@ -31,6 +31,7 @@ export interface Settings {
|
||||
isSinglePage: boolean
|
||||
version: string
|
||||
headingBlockTitle: string
|
||||
syncContent: boolean
|
||||
}
|
||||
|
||||
export const getQueryFromFilter = (
|
||||
@@ -136,6 +137,15 @@ export const settingsSchema = async (): Promise<SettingSchemaDesc[]> => [
|
||||
default: defaultHighlightTemplate,
|
||||
inputAs: 'textarea',
|
||||
},
|
||||
{
|
||||
key: 'syncContent',
|
||||
type: 'boolean',
|
||||
title: t('Sync article content'),
|
||||
description: t(
|
||||
'Sync article content into the content block. If this is not selected, only highlights will be synced.'
|
||||
),
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
key: 'advancedSettings',
|
||||
type: 'heading',
|
||||
|
||||
@@ -22,7 +22,6 @@ export type ArticleView =
|
||||
author?: string
|
||||
omnivoreUrl: string
|
||||
siteName: string
|
||||
content: string
|
||||
originalUrl: string
|
||||
note?: string
|
||||
type: PageType
|
||||
@@ -155,7 +154,6 @@ const createArticleView = (
|
||||
author: article.author,
|
||||
labels: article.labels,
|
||||
dateSaved,
|
||||
content: article.content,
|
||||
datePublished,
|
||||
note: note?.annotation ?? undefined,
|
||||
type: article.pageType,
|
||||
@@ -170,7 +168,7 @@ const createArticleView = (
|
||||
}
|
||||
}
|
||||
|
||||
export const renderArticleContent = (
|
||||
export const renderArticle = (
|
||||
template: string,
|
||||
article: Article,
|
||||
preferredDateFormat: string
|
||||
|
||||
@@ -43,5 +43,8 @@
|
||||
"Advanced Settings": "詳細設定",
|
||||
"API Endpoint": "APIエンドポイント",
|
||||
"Enter the Omnivore server's API endpoint here (default: https://api-prod.omnivore.app/api/graphql )": "OmnivoreサーバーのAPIエンドポイントをここに入力してください(デフォルト: https://api-prod.omnivore.app/api/graphql )",
|
||||
"Failed to create Omnivore page. Please check the pageName in the settings": "Omnivoreページの作成に失敗しました。設定のページ名を確認してください"
|
||||
}
|
||||
"Failed to create Omnivore page. Please check the pageName in the settings": "Omnivoreページの作成に失敗しました。設定のページ名を確認してください",
|
||||
"### Content": "### 内容",
|
||||
"Sync article content": "記事の内容を同期する",
|
||||
"Sync article content into the content block. If this is not selected, only highlights will be synced.": "記事の内容をコンテンツブロックに同期します。これが選択されていない場合、ハイライトのみが同期されます。"
|
||||
}
|
||||
|
||||
@@ -43,5 +43,8 @@
|
||||
"Advanced Settings": "高级设置",
|
||||
"API Endpoint": "API 终点",
|
||||
"Enter the Omnivore server's API endpoint here (default: https://api-prod.omnivore.app/api/graphql )": "在此处输入 Omnivore 服务器的 API 终点(默认: https://api-prod.omnivore.app/api/graphql )",
|
||||
"Failed to create Omnivore page. Please check the pageName in the settings": "创建 Omnivore 页面失败。请检查设置中的页面名称"
|
||||
}
|
||||
"Failed to create Omnivore page. Please check the pageName in the settings": "创建 Omnivore 页面失败。请检查设置中的页面名称",
|
||||
"### Content": "### 内容",
|
||||
"Sync article content": "同步文章内容",
|
||||
"Sync article content into the content block. If this is not selected, only highlights will be synced.": "将文章内容同步到内容块。如果未选择此选项,将仅同步高亮。"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user