Skip to content

Instantly share code, notes, and snippets.

View torantine's full-sized avatar

G. Blake Harrison-Lane torantine

View GitHub Profile
<%*
/*
Requires: Templater
This template will create new files containing the content between
each thematic break "---" in the current file (ignoring the metadata)
and add links to the new files in the current file.
If you don't like the result just undo a few times
and delete the newly created files.
@torantine
torantine / templater.makeYearOfFiles
Last active June 4, 2021 19:45
This templater template will create a years worth of files from the year you want in the folder you want. Copy the raw text into an md file in Obsidian.
<%*
// cleaner version can be made using moment.js
// format date to YYYY-MM-DD (date -> string)
function formatDate(date) {
// https://stackoverflow.com/questions/23593052/format-javascript-date-as-yyyy-mm-dd
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
# Get Word Count from Tagged Pages
## Search Tag
tagToSearchFor:: anotherTag
^ This inline metadata field is used as the tag that dataview searches the vault for. Write the name of the tag without the hash in front or `null` for all pages in your vault. You can use MetaEdit to change search term in preview mode. Search by other fields soon to come!
---
```dataviewjs
let text = app.workspace.activeLeaf.view.file.unsafeCachedData;
// thanks to https://www.tutorialspoint.com/how-to-count-a-number-of-words-in-given-string-in-javascript
text = text.replace(/(^\\s\*)|(\\s\*$)/gi,""); // remove the start and end spaces of the given string
text = text.replace(/\[ \]{2,}/gi," "); // reduce multiple spaces to a single space
text = text.replace(/\\n /,"\\n"); // exclude a new line with a start spacing
// thanks to Luke Leppan and the Better Word Count plugin
//This is templater template to copy and paste in an Obsidian .md file not JS, just nice for looking at the formatting << delete me!
<%*
// define function to replace timestamps in file
function replaceTimestamp () {
const regexHHMM = /(YT=\d\d:[0-5]\d)/g;
// change "YT=" if you want a different search term. currently videos cannot be longer than 99m59s
var content = tp.file.content; // *content of file*
var matches = content.match(regexHHMM); // *find all regex matches in file*
const matchesLength = matches.length; // *length of array containing all matches*