From c8fd1ec4879d9bac1436f72a9f013c7cd26d434a Mon Sep 17 00:00:00 2001 From: Karey Higuera Date: Thu, 18 Nov 2021 19:39:28 -0600 Subject: [PATCH] add alt_text to images when present --- manifest.json | 2 +- package.json | 2 +- src/models.ts | 1 + src/util.ts | 6 +++--- versions.json | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/manifest.json b/manifest.json index 5d60ed1..2b2f07e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-tweet-to-markdown", "name": "Tweet to Markdown", - "version": "1.1.4", + "version": "1.2.0", "minAppVersion": "0.12.16", "description": "Save tweets as Markdown files, along with their images, polls, etc.", "author": "kbravh", diff --git a/package.json b/package.json index f9be8ca..5a49025 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-tweet-to-markdown", - "version": "1.1.4", + "version": "1.2.0", "description": "Save tweets as beautiful markdown files in Obsidian (https://obsidian.md)", "main": "main.js", "engines": { diff --git a/src/models.ts b/src/models.ts index a243f26..834667e 100644 --- a/src/models.ts +++ b/src/models.ts @@ -38,6 +38,7 @@ export interface Media { media_key: string type: 'photo' | 'gif' | 'video' url?: string + alt_text?: string } export interface Mention { diff --git a/src/util.ts b/src/util.ts index 12bd4e0..8380054 100644 --- a/src/util.ts +++ b/src/util.ts @@ -35,7 +35,7 @@ export const getTweet = async (id: string, bearer: string): Promise => { 'user.fields': 'name,username,profile_image_url', 'tweet.fields': 'attachments,public_metrics,entities,conversation_id,referenced_tweets', - 'media.fields': 'url', + 'media.fields': 'url,alt_text', 'poll.fields': 'options', }) @@ -158,14 +158,14 @@ export const createMediaElements = ( ) switch (medium.type) { case 'photo': - return `\n![${medium.media_key}](${filepath})` + return `\n![${medium.alt_text ?? medium.media_key}](${filepath})` default: break } } else { switch (medium.type) { case 'photo': - return `\n![${medium.media_key}](${medium.url})` + return `\n![${medium.alt_text ?? medium.media_key}](${medium.url})` default: break } diff --git a/versions.json b/versions.json index 938a315..554b683 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "1.1.4": "0.12.16" + "1.2.0": "0.12.16" }