YukiGasai / obsidian-google-calendar

Add Google Calendar inside Obsidian
https://yukigasai.github.io/obsidian-google-calendar/
GNU General Public License v3.0
359 stars 25 forks source link

Frontmatter injection order of operations #168

Closed califa closed 1 year ago

califa commented 1 year ago

Hi! I'm trying to use Templater alongside this plugin (thanks for the help on that!) and am having some trouble controlling the frontmatter as both plugins are trying to inject their own.

This is the code I have:

<%* 
const {getEvent} = app.plugins.plugins["google-calendar"].api; 
const event = await getEvent("{{gEvent.id}}", "{{gEvent.parent.id}}");
%>
<% "---" %>
date: <%* tR += event.start.date ? 
window.moment(event.start.date).format("DD-MM-YYYY") : 
window.moment(event.start.dateTime).format("DD-MM-YYYY hh:mm") %>
title: <%event?.summary%>
<% "---" %>

And this is the output on a given event:

image

Is there a setting where I can insert the meeting-id myself so it doesn't conflict with the frontmatter I'm trying to add via templater?

Thank you!

pastorjack commented 1 year ago

I came here with the same problem. Being able to create my own frontmatter via template allows me to make the events show correctly in full calendar. It also allows lots of other opportunities to work with the frontmatter for other purposes.

YukiGasai commented 1 year ago

Hi, just switching the order of operation is not enough to detect the separated parts of the frontmatter. I updated the plugin so it will not try to insert a event-id into the frontmatter if it reads the event-id: text somewhere in the note. Which means, you can add the event-id into your template directly and it should work. Updated example:

<%* 
const {getEvent} = app.plugins.plugins["google-calendar"].api; 
const event = await getEvent("{{gEvent.id}}", "{{gEvent.parent.id}}");
%><% "---" %>
date: <%* tR += event.start.date ? 
window.moment(event.start.date).format("DD-MM-YYYY") : 
window.moment(event.start.dateTime).format("DD-MM-YYYY hh:mm") %>
title: <%event?.summary%>
event-id: <%event?.id%>
<% "---" %>
califa commented 1 year ago

This worked perfectly, thank you!

pastorjack commented 1 year ago

This is so perfect for me! Thank you!!! Here's my template that works well for my purposes:

<%*
const {getEvent} = this.app.plugins.plugins["google-calendar"].api;  
const event = await getEvent("{{gEvent.id}}", "{{gEvent.parent.id}}");
%><% "---" %>
title: <%event?.summary%>
event-id: <%event?.id%>
allDay: false
date: <%* tR += event.start.date ? 
window.moment(event.start.date).format("DD-MM-YYYY") : 
window.moment(event.start.dateTime).format("YYYY-MM-DD") %>
startTime: <%* tR += event.start.date ? 
window.moment(event.start.date).format("DD-MM-YYYY") : 
window.moment(event.start.dateTime).format("hh:mm") %>
endTime: <%
event.start.date 
? window.moment(event.end.date).format("DD-MM-YYYY") 
: window.moment(event.end.dateTime).format("hh:mm")
%>
<% "---" %>
# {{gEvent.summary}} 
{{gEvent.description}}
{{gEvent.location}}
<%
event.start.date 
? window.moment(event.start.date).format("DD-MM-YYYY") 
: window.moment(event.start.dateTime).format("dddd, MMMM Do, YYYY, hh:mm")
%> - <%
event.start.date 
? window.moment(event.end.date).format("DD-MM-YYYY") 
: window.moment(event.end.dateTime).format("hh:mm")
%> [Edit]({{gEvent.htmlLink}})

<%
tr = event?.attachments?.reduce((all,attachment) => `${all}- [${attachment.title}](${attachment.fileUrl})\n`,'') ?? ""
%>
# Attendees 
| Name | Status |
| --- | --- |
<%
tr = event?.attendees?.reduce((all,attendee) => `${all}|${attendee.displayName??attendee.email}|${attendee.responseStatus}|\n`,'') ?? ""
%>

# Agenda

# Action Items