Created
April 13, 2020 12:52
-
-
Save MuxinLee/3259539b20cb9e14fbfa48a300b300b4 to your computer and use it in GitHub Desktop.
getNotionPublicURL
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
<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> |
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
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