Skip to content

Commit

Permalink
[FEAT] date title placeholder (#23)
Browse files Browse the repository at this point in the history
* version bump so I don't forget to do it after

* add updated mock tweets and clean up type errors

* write tests for create filename function

* make timestamp format a required parameter

* update the readme with [[date]] instructions
  • Loading branch information
kbravh authored May 31, 2022
1 parent c9e4ab5 commit b809d0e
Show file tree
Hide file tree
Showing 17 changed files with 679 additions and 33 deletions.
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,23 @@ To download a tweet thread, paste the link to the **LAST** tweet in the thread,

![The modal to download a new tweet.](https://raw.githubusercontent.com/kbravh/obsidian-tweet-to-markdown/main/images/tweet_url_modal.png)

Once the tweet is downloaded, you'll be presented a window to set the name of the file that will be created. You can use the variables `[[handle]]`, `[[name]]`, `[[text]]`, and `[[id]]` when naming your file, which will be automatically replaced according to the following chart. The file extension `.md` will be added automatically.
Once the tweet is downloaded, you'll be presented a window to set the name of the file that will be created. You can use the variables `[[handle]]`, `[[name]]`, `[[text]]`, `[[date]]`, and `[[id]]` when naming your file, which will be automatically replaced according to the following chart. The file extension `.md` will be added automatically.

| Variable | Replacement |
|:---:|---|
|[[handle]]|The user's handle (the part that follows the @ symbol)|
|[[name]]|The user's name|
|[[id]]|The unique ID assigned to the tweet|
|[[text]]|The entire text of the tweet|
|`[[handle]]`|The user's handle (the part that follows the @ symbol)|
|`[[name]]`|The user's name|
|`[[id]]`|The unique ID assigned to the tweet|
|`[[text]]`|The entire text of the tweet (truncated to fit OS filename length restrictions)|
|`[[date]]`|The date that the tweet was created|

If the `[[date]]` variable is provided, it will by default use the locale and time format defined in your [settings](https://github.com/kbravh/obsidian-tweet-to-markdown#date-format) (it's towards the bottom of this readme).

- If you would like to use a different format, include it after the date with a semicolon: `[[date:LL]]`.
- If you would like a different locale, include it after the format with another semicolon: `[[date:LL:es]]`.
- If you want the same format as your settings but a different locale, just leave the format section blank: `[[date::es]]`.

Please check the `moment` documentation for a list of all available [locales](https://github.com/moment/moment/tree/develop/src/locale) and [formats](https://momentjs.com/docs/#/displaying/format/).

![The modal to name a downloaded tweet.](https://raw.githubusercontent.com/kbravh/obsidian-tweet-to-markdown/main/images/tweet_complete_modal.png)

Expand All @@ -77,14 +86,23 @@ On the Tweet to Markdown settings page in Obsidian, you can customize the way th

### Custom File Name

Tweets are, by default, saved with the filename `[[handle]] - [[id]].md`. You can instead enter your own format in the **Filename** field using the variables `[[name]]`, `[[handle]]`, `[[text]]`, and `[[id]]` in your filename, which will be automatically replaced according to the following chart. The file extension `.md` will be added automatically.
Tweets are, by default, saved with the filename `[[handle]] - [[id]].md`. You can instead enter your own format in the **Filename** field using the variables `[[name]]`, `[[handle]]`, `[[text]]`, ``[[date]]`, and `[[id]]` in your filename, which will be automatically replaced according to the following chart. The file extension `.md` will be added automatically.

| Variable | Replacement |
|:---:|---|
|[[handle]]|The user's handle (the part that follows the @ symbol)|
|[[name]]|The user's name|
|[[id]]|The unique ID assigned to the tweet|
|[[text]]|The entire text of the tweet (truncated to fit OS filename length restrictions)|
|`[[handle]]`|The user's handle (the part that follows the @ symbol)|
|`[[name]]`|The user's name|
|`[[id]]`|The unique ID assigned to the tweet|
|`[[text]]`|The entire text of the tweet (truncated to fit OS filename length restrictions)|
|`[[date]]`|The date that the tweet was created|

If the `[[date]]` variable is provided, it will by default use the locale and time format defined in your [settings](https://github.com/kbravh/obsidian-tweet-to-markdown#date-format) (it's towards the bottom of this readme).

- If you would like to use a different format, include it after the date with a semicolon: `[[date:LL]]`.
- If you would like a different locale, include it after the format with another semicolon: `[[date:LL:es]]`.
- If you want the same format as your settings but a different locale, just leave the format section blank: `[[date::es]]`.

Please check the `moment` documentation for a list of all available [locales](https://github.com/moment/moment/tree/develop/src/locale) and [formats](https://momentjs.com/docs/#/displaying/format/).

### Custom File Path

Expand Down
65 changes: 65 additions & 0 deletions __fixtures__/tweets/cashtag_tweet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {Tweet} from 'src/types/tweet'

export const cashtagTweet: Tweet = {
data: {
public_metrics: {
retweet_count: 0,
reply_count: 0,
like_count: 1,
quote_count: 0,
},
created_at: '2020-09-02T16:15:47.000Z',
id: '1301192107143561219',
entities: {
urls: [
{
start: 102,
end: 125,
url: 'https://t.co/qnyDphmJm2',
expanded_url:
'https://twitter.com/BTheriot2014/status/1301180406226513921',
display_url: 'twitter.com/BTheriot2014/s…',
},
],
hashtags: [
{
start: 22,
end: 31,
tag: 'cashtags',
},
{
start: 88,
end: 95,
tag: 'coffee',
},
],
cashtags: [
{
start: 52,
end: 57,
tag: 'SBUX',
},
],
},
conversation_id: '1301192107143561219',
text: 'Today I learned about #cashtags - and found out my $SBUX is in current tweet! Must be #coffee time! https://t.co/qnyDphmJm2',
referenced_tweets: [
{
type: 'quoted',
id: '1301180406226513921',
},
],
author_id: '1058876047465209856',
},
includes: {
users: [
{
id: '1058876047465209856',
username: 'Ceascape_ca',
name: 'ceascape.business.solutions',
profile_image_url:
'https://pbs.twimg.com/profile_images/1058877044015038464/u68hN9LW_normal.jpg',
},
],
},
}
81 changes: 81 additions & 0 deletions __fixtures__/tweets/image_tweet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {Tweet} from 'src/types/tweet'

export const ImageTweet: Tweet = {
data: {
created_at: '2020-08-10T15:30:23.000Z',
conversation_id: '1292845757297557505',
id: '1292845757297557505',
attachments: {
media_keys: ['3_1292845624120025090', '3_1292845644567269376'],
},
entities: {
annotations: [
{
start: 104,
end: 115,
probability: 0.9801,
type: 'Person',
normalized_text: 'Mary Douglas',
},
],
urls: [
{
start: 260,
end: 283,
url: 'https://t.co/O2P7WRO1XL',
expanded_url: 'http://maggieappleton.com/dirt',
display_url: 'maggieappleton.com/dirt',
},
{
start: 284,
end: 307,
url: 'https://t.co/PSk7lHiv7z',
expanded_url:
'https://twitter.com/Mappletons/status/1292845757297557505/photo/1',
display_url: 'pic.twitter.com/PSk7lHiv7z',
media_key: '3_1292845624120025090',
},
{
start: 284,
end: 307,
url: 'https://t.co/PSk7lHiv7z',
expanded_url:
'https://twitter.com/Mappletons/status/1292845757297557505/photo/1',
display_url: 'pic.twitter.com/PSk7lHiv7z',
media_key: '3_1292845644567269376',
},
],
},
author_id: '1343443016',
text: '"Dirt is matter out of place" - the loveliest definition of dirt you could hope for from anthropologist Mary Douglas in her classic 1966 book Purity and Danger\n\nHair on my head? Clean. Hair on the table? Dirty!\n\nIllustrating & expanding on her main ideas: https://t.co/O2P7WRO1XL https://t.co/PSk7lHiv7z',
public_metrics: {
retweet_count: 29,
reply_count: 11,
like_count: 191,
quote_count: 2,
},
},
includes: {
media: [
{
media_key: '3_1292845624120025090',
type: 'photo',
url: 'https://pbs.twimg.com/media/EfEcPs8XoAIXwvH.jpg',
},
{
media_key: '3_1292845644567269376',
type: 'photo',
url: 'https://pbs.twimg.com/media/EfEcQ5HX0AA2EvY.jpg',
},
],
users: [
{
username: 'Mappletons',
id: '1343443016',
name: 'Maggie Appleton 🧭',
profile_image_url:
'https://pbs.twimg.com/profile_images/1079304561892966406/1AHsGSnz_normal.jpg',
},
],
},
}
5 changes: 5 additions & 0 deletions __fixtures__/tweets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './cashtag_tweet'
export * from './image_tweet'
export * from './mentions_tweet'
export * from './poll_tweet'
export * from './tweet_thread'
77 changes: 77 additions & 0 deletions __fixtures__/tweets/mentions_tweet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {Tweet} from 'src/types/tweet'

export const MentionsTweet: Tweet = {
data: {
text: "I've just created a Node.js CLI tool to save tweets as Markdown, great for @NotionHQ, @RoamResearch, @obsdmd, and other Markdown based note-taking systems! https://t.co/9qzNhz5cmN",
public_metrics: {
retweet_count: 0,
reply_count: 0,
like_count: 0,
quote_count: 0,
},
created_at: '2020-09-09T17:55:42.000Z',
entities: {
urls: [
{
start: 156,
end: 179,
url: 'https://t.co/9qzNhz5cmN',
expanded_url: 'https://github.com/kbravh/tweet-to-markdown',
display_url: 'github.com/kbravh/tweet-t…',
images: [
{
url: 'https://pbs.twimg.com/news_img/1501819606129950722/opZrrpCT?format=jpg&name=orig',
width: 1280,
height: 640,
},
{
url: 'https://pbs.twimg.com/news_img/1501819606129950722/opZrrpCT?format=jpg&name=150x150',
width: 150,
height: 150,
},
],
status: 200,
title:
'GitHub - kbravh/tweet-to-markdown: A command line tool to convert Tweets to Markdown.',
description:
'A command line tool to convert Tweets to Markdown. - GitHub - kbravh/tweet-to-markdown: A command line tool to convert Tweets to Markdown.',
unwound_url: 'https://github.com/kbravh/tweet-to-markdown',
},
],
mentions: [
{
start: 75,
end: 84,
username: 'NotionHQ',
id: '708915428454576128',
},
{
start: 86,
end: 99,
username: 'RoamResearch',
id: '1190410678273626113',
},
{
start: 101,
end: 108,
username: 'obsdmd',
id: '1239876481951596545',
},
],
},
id: '1303753964291338240',
author_id: '1143604512999034881',
conversation_id: '1303753964291338240',
},
includes: {
users: [
{
username: 'kbravh',
name: 'Karey Higuera 🦈',
id: '1143604512999034881',
profile_image_url:
'https://pbs.twimg.com/profile_images/1163169960505610240/R8BoDqiT_normal.jpg',
},
],
},
}
48 changes: 48 additions & 0 deletions __fixtures__/tweets/poll_tweet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {Tweet} from 'src/types/tweet'

export const PollTweet: Tweet = {
data: {
conversation_id: '1029121914260860929',
id: '1029121914260860929',
created_at: '2018-08-13T21:45:59.000Z',
text: 'Which is Better?',
attachments: {
poll_ids: ['1029121913858269191'],
},
public_metrics: {
retweet_count: 7,
reply_count: 11,
like_count: 47,
quote_count: 2,
},
author_id: '4071934995',
},
includes: {
polls: [
{
id: '1029121913858269191',
options: [
{
position: 1,
label: 'Spring',
votes: 1373,
},
{
position: 2,
label: 'Fall',
votes: 3054,
},
],
},
],
users: [
{
id: '4071934995',
name: 'polls',
username: 'polls',
profile_image_url:
'https://pbs.twimg.com/profile_images/660160253913382913/qgvYqknJ_normal.jpg',
},
],
},
}
Loading

0 comments on commit b809d0e

Please sign in to comment.