Last active
July 5, 2022 15:43
-
-
Save ruter/3749de11dc990827887e44389698d5d1 to your computer and use it in GitHub Desktop.
A Slashy command script to set current page's icon and title to today.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------------------------------- | |
// CONFIGURATION SETTINGS | |
// ---------------------------------------------------------------------------------- | |
// The CORS Proxy | |
const CORS_PROXY = ""; | |
// Your Notion Internal Integration Token | |
// Ref. https://www.notion.so/my-integrations | |
const NOTION_TOKEN = ""; | |
const NOTION_API = CORS_PROXY + "https://api.notion.com/v1/pages/"; | |
const COLORS = ["red", "blue", "yellow", "green", "violet", "pink", "fuchsia", "grey"]; | |
let getDateStr = () => { | |
const options = { year: 'numeric', month: '2-digit', day: '2-digit' }; | |
return new Date().toLocaleDateString('sv-SE', options); | |
} | |
let getIconUrl = () => { | |
const color = COLORS[Math.floor((Math.random() * COLORS.length))]; | |
const today = getDateStr(); | |
let url = `https://api.wolai.com/v1/icon?type=2&locale=en&date=${today}&pro=0&color=${color}` | |
return url; | |
} | |
let getNotionPageId = () => { | |
return window.location.pathname.split('-').slice(-1)[0]; | |
} | |
const options = { | |
method: 'PATCH', | |
headers: { | |
Accept: 'application/json', | |
'Notion-Version': '2022-02-22', | |
'Content-Type': 'application/json', | |
Authorization: 'Bearer ' + NOTION_TOKEN, | |
}, | |
body: JSON.stringify({ | |
properties: { | |
title: { | |
title: [ | |
{ | |
type: "text", | |
text: { | |
content: getDateStr(), | |
link: null | |
}, | |
} | |
] | |
} | |
}, | |
icon: { | |
type: 'external', | |
external: { | |
url: getIconUrl() | |
} | |
} | |
}) | |
}; | |
fetch(NOTION_API + getNotionPageId(), options) | |
.then(response => response.json()) | |
.then(response => console.log(response)) | |
.catch(err => console.error(err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment