Skip to content

Commit

Permalink
add alt_text to images when present
Browse files Browse the repository at this point in the history
  • Loading branch information
kbravh committed Nov 19, 2021
1 parent 8f7f1fd commit c8fd1ec
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
1 change: 1 addition & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface Media {
media_key: string
type: 'photo' | 'gif' | 'video'
url?: string
alt_text?: string
}

export interface Mention {
Expand Down
6 changes: 3 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const getTweet = async (id: string, bearer: string): Promise<Tweet> => {
'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',
})

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"1.1.4": "0.12.16"
"1.2.0": "0.12.16"
}

0 comments on commit c8fd1ec

Please sign in to comment.