Insert moon phase in Daily Note with Templater

Hi folks :sun_with_face:

I finally implemented something i wanted to see in my daily notes for quite some time : the current moon phase!

In my note, today, it looks like this :

šŸŒ” Gibbeuse Croissante

Here is how i did it.


Concept

With the help of a javascript function, the moon phase is derived from the file’s date and inserted in a daily note through its template and Templater.

Requirements & Dependencies

Preliminary setup

  • Place the moon_phase.js script inside the folder of your choice. I chose Atlas/Ressources/scripts in my vault.
  • In the Templater settings, under User Scripts Functions, locate the scripts folder and Refresh šŸ”„ the Detected User Scripts.

Template implementation

This implementation is relative to the file’s title.
For my usage, i wanted to insert the moon phase inside my daily notes, which have a YYYY-MM-DD file title format. I already use Templater to generate various elements of the note based on the file title (it allows to create the file whenever i want and still have relative dates inside it).

  • Open your daily note’s template ― i won’t detail how to set it up if you’re not using any yet, it’s easy enough to find around here.
  • On a new line, or wherever you want the moon phase displayed, insert :
    <% tp.user.moon_phase(tp) %>
  • For the most basic (northern hemisphere, english) implementation, that’s enough!

Customization

In order for a bit more control over the information displayed, I was about to write that you could play inside the javascript file; but i actually took the time and fun to expand it so that we can instead provide the function with optional parameters.

<% tp.user.moon_phase(tp, language, display, separator, title_format, hemisphere) %>

  • language : the text’s language; currently, only "en" (default), "fr", and "es" are supported
  • display : what is being rendered
    • "et" for emoji and text (default)
    • "te" for text and emoji
    • "e" for emoji only
    • "t" for text only
  • separator : the character between emoji and text; default : " " (space)
  • title_format : your daily note’s title format; default : "YYYY-MM-DD"
  • hemisphere : the hemisphere you are in; will influence which emoji is shown, as the moon is viewed upside down; default : "N"

If you don’t provide any other parameter than the mandatory tp, it will default to :
<% tp.user.moon_phase(tp, "en", "et", " ", "YYYY-MM-DD", "N") %>

If you want to provide only some parameters, you have to enter them in order, and can skip the ones you do not need to replace by writing undefined.

For example, Chile’s moon phase, with emoji and text separated with a bar :
<% tp.user.moon_phase(tp, "es", undefined, " | ", undefined, "S") %>

will be interpreted as :
<% tp.user.moon_phase(tp, "es", "et", " | ", "YYYY-MM-DD", "S") %>

and rendered today as :
šŸŒ– | Luna Gibosa Creciente

For further customization, for example to change the text’s language or which emojis are used (why though ?), feel free to modify the javascript file, which you can open and save in a text editor.

Thanks and references

Contribute

Please mention any bug you find, or useful language translations that could be implemented.
For my use it works like it is, so i can’t promise any further update. But i might, once in a while.
I am not a professional developper, so there might be innefficiencies in the code, but i believe it’s good enough!


Hope you find it useful and informative!

Ji :full_moon_with_face:

7 Likes

Thanks. This was just what I needed and instructions were clear for a non-coder. Appreciated.

1 Like

Thank you for sharing this! :folded_hands:

1 Like

Hey thank for the code. It’s great! May I make a request?

Each full moon of the year has it own name. (which can be found on the Royal Museums Greenwich website - however I can’t like it for some reason)

Could you implements this into the code? The Blue Moon looks the trickiest to get right. I think the more contemporary definition would be easier.

1 Like

Hi, thank you for this. I was looking for something like this. I have a bug though. I’m fairly new to Obsidian so I may have missed something but I have the js file in a scripts folder and templater added it to the detected scripts when I did a refresh. I put the basic prompt in my note and when I trigger Templater I get the following error: Templater Error: Invalid reference date format, try specifing one with the argument ā€˜reference_format’. Did I miss something or is there something else I can try?

Thanks

Hey there!

Sorry it took me so long to reply. I actually just saw you guys’ replies exactly one year after i created this script, yesterday, as i was reading my ā€œthe year beforeā€ note.

Well, you put me up on a task, wow, haha.
But i did it, and enjoyed the process of making the script even better and easier to use.

I cannot update the original post, so it is now better to go and find the whole project and documentation on Github :

Tell me if that works for you!

I will be back with another script eventually, that i created shortly after this one : moon transits !

Hi!

I believe this is due to the date format you use in your daily note’s title being different from the one specified by default in the function (ā€œYYYY-MM-DDā€).

Install the new version that came out today and try to use :

<% tp.user.moon_phase(tp, { title_format : "myTitleFormat" }) %>

replacing myTitleFormat with your notes’ title format (which could be different, like "YY MM DD")

Alright, new upgrade available on the github page : Sign Transits ! :aries:

I had been using a parallel script for about a year, and this new work on the full moon names triggered me to merge both scripts in one, more optimized function.

If anyone is following this and used the script before, there is a slight change to be made :

  • the name of the script changed from moon_phase to obsidian_moons
  • the parameters are now in an options object, more clear and flexible
  • the format parameter now replaces display, in a more advanced way

Please read the documentation for everything you need to know to get started with inserting the moon’s phase, along with the full moon name and the moon’s sign, in your daily notes !

I will be posting here when bigger upgrades happen (like a new feature); for bug fixes or small updates, it will only be seen on the github page; follow the project up there, and keep an eye out for it!

Thank you for your interest in the moon,

Ji :new_moon_face:

2 Likes