Skip to content

Commit

Permalink
fix timezone of folder date, add commands to include activity links
Browse files Browse the repository at this point in the history
  • Loading branch information
saadsaifse committed Oct 14, 2023
1 parent 0261a17 commit 728273c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
32 changes: 32 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PluginSettingTab,
Setting,
addIcon,
Editor
} from 'obsidian'
import { AuthenticationConfig } from 'strava-v3'
import { fetchAthleteActivities, fetchAthleteActivity } from 'src/retriever'
Expand Down Expand Up @@ -75,6 +76,22 @@ export default class StravaActivities extends Plugin {
callback: () => auth.authenticate(this.settings.authSettings),
})

this.addCommand({
id: 'insert-todays-strava-activities',
name: "Insert today's Strava activities",
editorCallback: (editor: Editor) => {
this.handleInsertStravaActivitiesCommand(editor, false)
},
})

this.addCommand({
id: 'insert-todays-strava-activity-maps',
name: "Insert today's Strava activity maps",
editorCallback: (editor: Editor) => {
this.handleInsertStravaActivitiesCommand(editor, true)
},
})

// this.addCommand({
// id: 'activity-details-command',
// name: 'Retrieve detailed activities',
Expand Down Expand Up @@ -135,6 +152,21 @@ export default class StravaActivities extends Plugin {
)
}

handleInsertStravaActivitiesCommand(editor: Editor, onlyMaps: boolean) {
const currentDate = DateTime.now().toISODate() ?? ''
const activityFolderPaths = this.fileManager.getChildrenPathsInFolder(currentDate)
let content = "## Today's Strava Activities\n"
for (const path of activityFolderPaths) {
console.log(path)
content += onlyMaps ? `\n![[${path}/Summary#Map]]\n` : `\n![[${path}/Summary]]\n`
}
content+='\n'
editor.replaceRange(
content,
editor.getCursor()
);
}

onunload() {
this.settings = DEFAULT_SETTINGS
this.saveSettings()
Expand Down
10 changes: 9 additions & 1 deletion src/fileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class FileManager {
try {
const activityDates = _.groupBy(
activities,
(activity) => activity.start_date.split('T')[0]
(activity) => activity.start_date_local.split('T')[0]
)
for (const activityDate in activityDates) {
await this.createFolderIfNonExistent(this.rootFolder)
Expand Down Expand Up @@ -168,4 +168,12 @@ export default class FileManager {
const fileContents = `${activityDetails}\n${mapFileContents}## Activity\n${activityContents}\n`
return fileContents
}

getChildrenPathsInFolder(folderName: string) {
const folder = this.vault.getAbstractFileByPath(path.join(this.rootFolder, folderName))
if (!(folder instanceof TFolder)) {
return []
}
return folder.children.map(f => f.path)
}
}

0 comments on commit 728273c

Please sign in to comment.