From 8ccb67c822dda87457ae1396dee7cae9c124785f Mon Sep 17 00:00:00 2001 From: tomoyane Date: Mon, 15 Apr 2024 20:30:16 +0900 Subject: [PATCH 1/2] docs: update readme, commentout --- README.md | 27 +++++++++++++++++++++++++-- src/config/proxyConfig.js | 5 ++++- src/expressApp.js | 2 +- src/lib/htmlParser.js | 28 ++++++++++++++-------------- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 67774fa..20977c6 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ npm run start_proxy > notion-proxy@1.0.0 start > node src/index.js -Proxy listening at localhost:3456, NotionId: f1db0cfbe246475784c67f279289abea + +Listening at localhost:3456 by NotionProxy. NotionId: f1db0cfbe246475784c67f279289abea ``` Start proxy binary. @@ -67,9 +68,22 @@ npm install -g pkg npm run build ./notion-proxy -Proxy listening at localhost:3456, NotionId: f1db0cfbe246475784c67f279289abea +Listening at localhost:3456 by NotionProxy. NotionId: f1db0cfbe246475784c67f279289abea ``` +Start proxy with AUTO_SET_OG_TAG for debug. + +```bash +export AUTO_SET_OG_TAG='true'; npm run start_proxy + +> notion-proxy@1.0.0 start +> node src/index.js + +Successful automatic fetched of OGP tag. Title: Re:Earth Documentation, Image: http://localhost:3456/image/ht..., Icon: http://localhost:3456/image/ht... +Listening at localhost:3456 by NotionProxy. NotionId: f1db0cfbe246475784c67f279289abea +``` + + ## Proxy example with your domain ```bash @@ -79,3 +93,12 @@ export IS_TLS="true" && \ export AUTO_SET_OG_TAG="true" && \ npm run start_proxy ``` + +## How to contribute + +1. Fork or clone the project +2. Create your feature branch and Commit your changes +3. Push to the branch +4. Open a new pull request + +[MIT License](LICENSE) \ No newline at end of file diff --git a/src/config/proxyConfig.js b/src/config/proxyConfig.js index 9d3d0f1..0cc2625 100644 --- a/src/config/proxyConfig.js +++ b/src/config/proxyConfig.js @@ -1,3 +1,6 @@ +/** + * See README about environment variable + */ class ProxyConfig { constructor() { this.googleFont = process.env.GOOGLE_FONT || ''; @@ -16,7 +19,7 @@ class ProxyConfig { } const protocol = this.isTls === 'true' ? 'https' : 'http'; - const url = `${protocol}://${this.domain}`; + const url = `${protocol}NotionProxy://${this.domain}`; const twitterCard = process.env.TWITTER_CARD || 'summary_large_image'; const pageTitle = process.env.OG_TAG_TITLE || ''; const pageDesc = process.env.OG_TAG_DESC || ''; diff --git a/src/expressApp.js b/src/expressApp.js index 8271d9b..d9de1d3 100644 --- a/src/expressApp.js +++ b/src/expressApp.js @@ -44,7 +44,7 @@ function main() { }) app.listen(Number(proxyConfig.proxyPort), async () => { await proxy.reloadProxyConfig(); - console.log(`NotionProxy listening at localhost:${proxyConfig.proxyPort}, NotionId: ${proxyConfig.notionPageId}`) + console.log(`Listening at localhost:${proxyConfig.proxyPort} by NotionProxy. NotionId: ${proxyConfig.notionPageId}`) }) } diff --git a/src/lib/htmlParser.js b/src/lib/htmlParser.js index 350bf73..6c634d7 100644 --- a/src/lib/htmlParser.js +++ b/src/lib/htmlParser.js @@ -34,9 +34,10 @@ class HtmlParser { this.slugToPage = stp; } - // Note - // Replace og:image data without dom because set original image url. - // If it uses DOM, the url is escaped. + /** + * Replace og:image data without dom because set original image url. + * If it uses DOM, the url is escaped. + */ replaceMetaImageWithoutDom(htmlStr) { if (this.pageImageUrl !== '') { htmlStr = htmlStr.replace(/(]*>)/g, `$1${this.pageImageUrl}$3`); @@ -45,9 +46,10 @@ class HtmlParser { return htmlStr; } - // Note - // Replace icon data without dom because set original icon url. - // If it uses DOM, the url is escaped. + /** + * Replace icon data without dom because set original icon url. + * If it uses DOM, the url is escaped. + */ replaceLinkIconWithoutDom(htmlStr) { if (this.iconUrl !== '') { const notionDefaultType = "image/x-icon"; @@ -65,10 +67,11 @@ class HtmlParser { return htmlStr; } - // Note - // Insert icon tag before shortcut icon tag if this.iconUrl is existed - // Also, Remove shortcut icon tag for notion rendering - // It seems that Notion's JavaScript monitors shortcut icon tag. And render the notion icon + /** + * Insert icon tag before shortcut icon tag if this.iconUrl is existed + * Also, Remove shortcut icon tag for notion rendering + * It seems that Notion's JavaScript monitors shortcut icon tag. And render the notion icon + */ parseShortCutIcon(document) { const shortcutElement = document.querySelector('link[rel="shortcut icon"]'); if (shortcutElement && this.iconUrl !== '') { @@ -117,8 +120,7 @@ class HtmlParser { if (element.getAttribute('name') === 'apple-itunes-app') { element.remove(); } - } catch (e) { - console.log(e) + } catch { } } @@ -210,8 +212,6 @@ class HtmlParser { arguments[1] = arguments[1].replace('${protocol}://${this.domain}', 'www.notion.so'); return open.apply(this, [].slice.call(arguments)); }; - - document.notionPageID = getPage(); ${this.customScript}` } From 81a4f8757787ce4a023659858cff040b5142cc82 Mon Sep 17 00:00:00 2001 From: tomoyane Date: Mon, 15 Apr 2024 20:34:16 +0900 Subject: [PATCH 2/2] fix test --- src/lib/htmlParser.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/htmlParser.test.js b/src/lib/htmlParser.test.js index 426408c..9526c09 100644 --- a/src/lib/htmlParser.test.js +++ b/src/lib/htmlParser.test.js @@ -149,8 +149,6 @@ test('Parse html for Notion', () => { arguments[1] = arguments[1].replace('https://eukarya.io', 'www.notion.so'); return open.apply(this, [].slice.call(arguments)); }; - - document.notionPageID = getPage(); `); });