From b7c6ced0f3da49014c8534d1207553cfb957f231 Mon Sep 17 00:00:00 2001 From: Brian Joseph Petro Date: Wed, 18 Dec 2024 19:30:53 -0500 Subject: [PATCH] Refactor SmartBlock and SmartSource classes to remove deprecated get_content method and improve missing block handling - Eliminated the deprecated get_content method from SmartBlock and SmartSource, encouraging the use of read instead. - Updated render functions in entity and source components to handle errors more gracefully when retrieving content, providing a fallback message for "BLOCK NOT FOUND". --- smart-blocks/smart_block.js | 7 ------- smart-entities/components/entity.js | 17 +++++++++++++---- smart-sources/components/source.js | 17 +++++++++++++---- smart-sources/smart_source.js | 7 ------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/smart-blocks/smart_block.js b/smart-blocks/smart_block.js index 21c9047f..8c183aaf 100644 --- a/smart-blocks/smart_block.js +++ b/smart-blocks/smart_block.js @@ -436,13 +436,6 @@ export class SmartBlock extends SmartEntity { // DEPRECATED - /** - * @async - * @deprecated Use `read` instead. - * @returns {Promise} A promise that resolves with the content of the block or "BLOCK NOT FOUND". - */ - async get_content() { return (await this.read()) || "BLOCK NOT FOUND (run \"Prune\" to remove)"; } - /** * @deprecated Use `source` instead. * @readonly diff --git a/smart-entities/components/entity.js b/smart-entities/components/entity.js index 3e55c189..07136646 100644 --- a/smart-entities/components/entity.js +++ b/smart-entities/components/entity.js @@ -1,8 +1,17 @@ export async function render(entity, opts = {}) { - const markdown = should_render_embed(entity) - ? entity.embed_link - : process_for_rendering(await entity.get_content()) - ; + let markdown; + if(should_render_embed(entity)) markdown = entity.embed_link; + else{ + try{ + markdown = process_for_rendering(await entity.read()) + } catch (e) { + if(e.message.includes('BLOCK NOT FOUND')){ + markdown = "BLOCK NOT FOUND (run \"Prune\" to remove)"; + } else { + throw e; + } + } + } let frag; if(entity.env.settings.smart_view_filter.render_markdown) frag = await this.render_markdown(markdown, entity); else frag = this.create_doc_fragment(markdown); diff --git a/smart-sources/components/source.js b/smart-sources/components/source.js index d671bdb3..e00eb1bc 100644 --- a/smart-sources/components/source.js +++ b/smart-sources/components/source.js @@ -4,10 +4,19 @@ import { post_process, } from "smart-entities/components/entity.js"; export async function render(source, opts = {}) { - const markdown = should_render_embed_source(source) - ? source.embed_link - : process_for_rendering(await source.get_content()) - ; + let markdown; + if(should_render_embed(entity)) markdown = entity.embed_link; + else{ + try{ + markdown = process_for_rendering(await entity.read()) + } catch (e) { + if(e.message.includes('BLOCK NOT FOUND')){ + markdown = "BLOCK NOT FOUND (run \"Prune\" to remove)"; + } else { + throw e; + } + } + } let frag; if(source.env.settings.smart_view_filter.render_markdown) frag = await this.render_markdown(markdown, source); else frag = this.create_doc_fragment(`${markdown}`); diff --git a/smart-sources/smart_source.js b/smart-sources/smart_source.js index 5ecdaf9c..f37578da 100644 --- a/smart-sources/smart_source.js +++ b/smart-sources/smart_source.js @@ -633,13 +633,6 @@ export class SmartSource extends SmartEntity { // DEPRECATED methods - /** - * @async - * @deprecated Use `read` instead. - * @returns {Promise} A promise that resolves with the content of the block or "BLOCK NOT FOUND". - */ - async get_content() { return (await this.read()) || "SOURCE NOT FOUND (run \"Prune\" to remove)"; } - /** * @deprecated Use `source` instead. * @readonly