const MY_DOMAIN = 'rezaarkan.com'; const SLUG_TO_PAGE = { '': '882cd6dd6e1e482d823b464f326213e5', 'now': '25b7df64071d420d8f609bf76d9f4114', 'portfolio': '6000547bed0d441793bfba1498c063e2', 'resume': '0934b80d2d1544f99dedadb00be9d146', 'recommendations': '29115129efa44f1a870f390dd2c0a6c0', 'photos': 'e78c0492a5ec486aa51f4cdb2c6f4603', 'blog': '29bb193c1a104ba2b832788b57d58cd6', 'bookmarks': 'e31f043461cd4739b9ec967cb36c0cba', 'contact': '15364eee2c8b41188a069184f9e108be', }; const ERROR_PAGE = ''; const PAGE_TITLE = 'Reza Arkan'; const PAGE_DESCRIPTION = 'Design / People / Tech'; const FAVICON_URL = 'https://drive.google.com/uc?id=12MYHtCw_uU3j9eyQ60vBLPe5R74gPIaX'; const IOS_ICON_URL = 'https://drive.google.com/uc?id=14LEFgUMPDiOf8iND-ldq8QKwtksLdkm2'; const OG_URL = 'https://rezaarkan.com'; const OG_TYPE = 'website'; const OG_IMAGE_URL = 'https://i.imgur.com/WgH50dv.jpg'; const META_TWITTER_CARD = 'summary'; const META_TWITTER_SITE = '@rezaarkan'; const META_TWITTER_TITLE = PAGE_TITLE; const META_TWITTER_DESC = PAGE_DESCRIPTION; const META_TWITTER_IMAGE = 'https://i.imgur.com/15A1v9d.jpg'; const META_TWITTER_URL = 'https://rezaarkan.com'; const GOOGLE_FONT = 'Poppins'; const CUSTOM_SCRIPT = ` `; const CUSTOM_CSS = `.notion-frame{background-image:linear-gradient(180deg,#fdfbfb 0,#ebedee 100%)!important}@keyframes gradient{0%{background-position:0 50%!important}50%{background-position:100% 50%}100%{background-position:0 50%}}.notion-page-content{padding-bottom:2.5rem!important;padding-top:2.5rem!important;background:#fff;border-radius:1rem;margin:-2.75rem 0 10vh 0}.notion-page-block{position:relative}.notion-scroller>[style="width: 100%; font-size: 14px;"]{margin-bottom:1.5rem}.notion-image-block{pointer-events:none!important}.notion-image-block img{pointer-events:none!important}.notion-callout-block>div>div{border-radius:.5rem!important}.notion-peek-renderer{background:#142025!important;transition:.3s}.notion-peek-renderer>div:nth-child(2){border-radius:.5rem!important;overflow:hidden}.notion-gallery-view>div>div>a{border-radius:.5rem!important}.notion-gallery-view>div>div>a:hover{opacity:.75}[data-block-id=c7ef4bd9-4069-480b-a481-3533903733e8]>div>div:nth-child(even),[data-block-id=f34cdbc9-8cd0-42aa-8189-3aa368fd0f37]>div>div:nth-child(even){display:none!important}@media only screen and (min-width:50em){[data-block-id=c7ef4bd9-4069-480b-a481-3533903733e8]>div>div:nth-child(even),[data-block-id=f34cdbc9-8cd0-42aa-8189-3aa368fd0f37]>div>div:nth-child(even){display:block!important}}[data-block-id=c7ef4bd9-4069-480b-a481-3533903733e8]>div>div:nth-child(odd),[data-block-id=f34cdbc9-8cd0-42aa-8189-3aa368fd0f37]>div>div:nth-child(odd){display:inline-block!important;max-width:50%!important}@media only screen and (min-width:50em){[data-block-id=c7ef4bd9-4069-480b-a481-3533903733e8]>div>div:nth-child(odd),[data-block-id=f34cdbc9-8cd0-42aa-8189-3aa368fd0f37]>div>div:nth-child(odd){display:block!important}}[data-block-id="971194ae-0c81-4fc6-a386-382167111c79"]{display:none}@media only screen and (min-width:50em){[data-block-id="971194ae-0c81-4fc6-a386-382167111c79"]{display:block;text-align:right;margin-top:-5.825rem!important;font-size:4rem}}[data-block-id=fcce5ac2-0901-4e52-a247-4684ece3df01]{font-size:.875rem;text-align:center}[data-block-id=fcce5ac2-0901-4e52-a247-4684ece3df01] .notion-record-icon{display:none!important}[data-block-id="6aa56b96-f6bf-4590-82c4-adca0c85b920"]{text-align:center}[data-block-id="6f58376d-b7c3-47a6-8720-d537db62ebf0"]{text-align:center;margin-bottom:-3.5rem!important}[data-block-id="6d7f9450-7f4e-4b6e-a9b8-45bccd9bfdd5"]{text-align:center;font-size:.875rem}[data-block-id="75a3b99e-f428-430d-a87b-3d5242fe5cce"]{text-align:right;padding-top:1rem}[data-block-id="51ee9852-027b-450e-aa4e-f6f0a1861ec2"]>div:first-child,[data-block-id=ec104b15-ff6e-4400-a848-a88f6139e1ff]>div:first-child,[data-block-id=f70889a1-feaa-4a1d-b00c-d4ee6e29689d]>div:first-child{min-height:0!important}[data-block-id="51ee9852-027b-450e-aa4e-f6f0a1861ec2"]>div:first-child>div,[data-block-id=ec104b15-ff6e-4400-a848-a88f6139e1ff]>div:first-child>div,[data-block-id=f70889a1-feaa-4a1d-b00c-d4ee6e29689d]>div:first-child>div{display:none!important}@media only screen and (min-width:50em){[data-block-id=ec104b15-ff6e-4400-a848-a88f6139e1ff]{grid-template-columns:repeat(auto-fill,minmax(30%,1fr))!important;grid-auto-rows:auto!important;gap:1.5rem!important}}[data-block-id="183d187c-7b2c-4ce4-9d56-13d715eb2e9b"],[data-block-id="566014b3-8ba6-448f-b305-717f947ca58a"],[data-block-id="99a71a4b-08f7-4c99-945a-ddfbc9df0a1b"],[data-block-id=a1dd0805-87b2-444e-8a6b-90ce0086a1c3],[data-block-id=afad12b7-f88f-419c-9a7f-7e621018b287],[data-block-id=e8e72e41-d5b4-4987-a016-44f8f489b53f],[data-block-id=ff122c47-f4fe-4b7f-b827-703883217388]{display:none!important}[data-block-id="00b8412b-49d8-4a22-a739-a4f666fbd082"]~div img{border-radius:.5rem!important}[data-block-id=e0fa74a3-dfc2-4b66-bcd9-30abfced1863]~div img{border-radius:.5rem!important}[data-block-id="8a0b343f-5acc-4095-9fce-266148517eda"]{display:none!important}`; const PAGE_TO_SLUG = {}; const slugs = []; const pages = []; Object.keys(SLUG_TO_PAGE).forEach(slug => { const page = SLUG_TO_PAGE[slug]; slugs.push(slug); pages.push(page); PAGE_TO_SLUG[page] = slug; }); addEventListener('fetch', event => { event.respondWith(fetchAndApply(event.request)); }); function generateSitemap() { let sitemap = ''; slugs.forEach( (slug) => (sitemap += 'https://' + MY_DOMAIN + '/' + slug + '') ); sitemap += ''; return sitemap; } const corsHeaders = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, HEAD, POST, PUT, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type', }; function handleOptions(request) { if (request.headers.get('Origin') !== null && request.headers.get('Access-Control-Request-Method') !== null && request.headers.get('Access-Control-Request-Headers') !== null) { // Handle CORS pre-flight request. return new Response(null, { headers: corsHeaders }); } else { // Handle standard OPTIONS request. return new Response(null, { headers: { 'Allow': 'GET, HEAD, POST, PUT, OPTIONS', } }); } } async function fetchAndApply(request) { if (request.method === 'OPTIONS') { return handleOptions(request); } let url = new URL(request.url); if (url.pathname === '/robots.txt') { return new Response('Sitemap: https://' + MY_DOMAIN + '/sitemap.xml'); } if (url.pathname === '/sitemap.xml') { let response = new Response(generateSitemap()); response.headers.set('content-type', 'application/xml'); return response; } let fullPathname = request.url.replace("https://" + MY_DOMAIN, ""); const notionUrl = 'https://www.notion.so' + fullPathname; let response; if (url.pathname.startsWith('/app') && url.pathname.endsWith('js')) { response = await fetch(notionUrl); let body = await response.text(); response = new Response(body.replace(/www.notion.so/g, MY_DOMAIN).replace(/notion.so/g, MY_DOMAIN), response); response.headers.set('Content-Type', 'application/x-javascript'); } else if ((url.pathname.startsWith('/api'))) { // Forward API response = await fetch(notionUrl, { body: request.body, headers: { 'content-type': 'application/json;charset=UTF-8', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36' }, method: 'POST', }); response = new Response(response.body, response); response.headers.set('Access-Control-Allow-Origin', '*'); } else if (slugs.indexOf(url.pathname.slice(1)) > -1) { const pageId = SLUG_TO_PAGE[url.pathname.slice(1)]; return Response.redirect('https://' + MY_DOMAIN + '/' + pageId, 301); } else if (pages.indexOf(url.pathname.slice(1)) === -1 && url.pathname.slice(1).match(/[0-9a-f]{32}/)) { return Response.redirect('https://' + MY_DOMAIN + '/' + ERROR_PAGE); } else { response = await fetch(notionUrl, { body: request.body, headers: request.headers, method: request.method, }); response = new Response(response.body, response); response.headers.delete('Content-Security-Policy'); response.headers.delete('X-Content-Security-Policy'); } return appendJavascript(response, SLUG_TO_PAGE); } class MetaRewriter { element(element) { if (PAGE_TITLE !== '') { if (element.getAttribute('property') === 'og:title' || element.getAttribute('property') === 'og:site_name' || element.getAttribute('name') === 'twitter:title') { element.setAttribute('content', PAGE_TITLE); } if (element.tagName === 'title') { element.setInnerContent(PAGE_TITLE); } } if (PAGE_DESCRIPTION !== '') { if (element.getAttribute('name') === 'description' || element.getAttribute('property') === 'og:description' || element.getAttribute('name') === 'twitter:description') { element.setAttribute('content', PAGE_DESCRIPTION); } } if (element.getAttribute('property') === 'og:url') { element.setAttribute('content', OG_URL); } if (element.getAttribute('name') === 'apple-itunes-app') { element.remove(); } if (element.getAttribute('property') === 'og:type') { element.setAttribute('content', OG_TYPE); } if (element.getAttribute('property') === 'og:image') { element.setAttribute('content', OG_IMAGE_URL); } if (element.tagName === 'link' && element.getAttribute('rel') === 'shortcut icon') { element.setAttribute('href', FAVICON_URL); } if (element.tagName === 'link' && element.getAttribute('rel') === 'apple-touch-icon') { element.setAttribute('href', IOS_ICON_URL); } if (element.getAttribute('name') === 'twitter:card') { element.setAttribute('content', META_TWITTER_CARD); } if (element.getAttribute('name') === 'twitter:site') { element.setAttribute('content', META_TWITTER_SITE); } if (element.getAttribute('name') === 'twitter:image') { element.setAttribute('content', META_TWITTER_IMAGE); } if (element.getAttribute('name') === 'twitter:url') { element.setAttribute('content', META_TWITTER_URL); } } } class HeadRewriter { element(element) { if (GOOGLE_FONT !== '') { element.append(` `, { html: true }); } element.append(``, { html: true }) } } class BodyRewriter { constructor(SLUG_TO_PAGE) { this.SLUG_TO_PAGE = SLUG_TO_PAGE; } element(element) { element.append(` ${CUSTOM_SCRIPT}`, { html: true }); } } async function appendJavascript(res, SLUG_TO_PAGE) { return new HTMLRewriter() .on('title', new MetaRewriter()) .on('meta', new MetaRewriter()) .on('link', new MetaRewriter()) .on('head', new HeadRewriter()) .on('body', new BodyRewriter(SLUG_TO_PAGE)) .transform(res); }