Skip to content

Instantly share code, notes, and snippets.

@MuxinLee
Created April 13, 2020 12:52
Show Gist options
  • Save MuxinLee/3259539b20cb9e14fbfa48a300b300b4 to your computer and use it in GitHub Desktop.
Save MuxinLee/3259539b20cb9e14fbfa48a300b300b4 to your computer and use it in GitHub Desktop.
getNotionPublicURL
<input id="input"></input>
<button type="checkbox" id="myCheck" onClick="myFunction()">
</button>
<p id="p"></p>
<script>
function myFunction() {
let url = parseImageUrl(document.getElementById("input").value); console.log(url);
document.getElementById("p").innerHTML = url;
}
</script>
const NOTION_BASE_URL = "https://www.notion.so";
const parseImageUrl = (url, width) => {
let rUrl;
if (url.startsWith("https://s3")) {
let [parsedOriginUrl] = url.split("?");
rUrl = `${NOTION_BASE_URL}/image/${encodeURIComponent(
parsedOriginUrl
).replace("s3.us-west", "s3-us-west")}`;
} else if (url.startsWith("/image")) {
rUrl = `${NOTION_BASE_URL}${url}`;
} else {
rUrl = url;
}
if (width) {
return `${rUrl}?width=${width}`;
} else {
return rUrl;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment