Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from eukarya-inc/update-doc
Browse files Browse the repository at this point in the history
docs: update readme, commentout
  • Loading branch information
tomoyane authored Apr 15, 2024
2 parents 5a4cb9d + 81a4f87 commit 1c4e734
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ npm run start_proxy

> [email protected] start
> node src/index.js
Proxy listening at localhost:3456, NotionId: f1db0cfbe246475784c67f279289abea

Listening at localhost:3456 by NotionProxy. NotionId: f1db0cfbe246475784c67f279289abea
```

Start proxy binary.
Expand All @@ -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

> [email protected] 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
Expand All @@ -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)
5 changes: 4 additions & 1 deletion src/config/proxyConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* See README about environment variable
*/
class ProxyConfig {
constructor() {
this.googleFont = process.env.GOOGLE_FONT || '';
Expand All @@ -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 || '';
Expand Down
2 changes: 1 addition & 1 deletion src/expressApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
})
}

Expand Down
28 changes: 14 additions & 14 deletions src/lib/htmlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(<meta property="og:image" content=")([^"]*)("[^>]*>)/g, `$1${this.pageImageUrl}$3`);
Expand All @@ -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";
Expand All @@ -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 !== '') {
Expand Down Expand Up @@ -117,8 +120,7 @@ class HtmlParser {
if (element.getAttribute('name') === 'apple-itunes-app') {
element.remove();
}
} catch (e) {
console.log(e)
} catch {
}
}

Expand Down Expand Up @@ -210,8 +212,6 @@ class HtmlParser {
arguments[1] = arguments[1].replace('${protocol}://${this.domain}', 'www.notion.so');
return open.apply(this, [].slice.call(arguments));
};
<!-- required for comments identification -->
document.notionPageID = getPage();
</script>${this.customScript}`
}

Expand Down
2 changes: 0 additions & 2 deletions src/lib/htmlParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
<!-- required for comments identification -->
document.notionPageID = getPage();
</script><script>console.log("hello world custom script")</script></body></html>`);
});

Expand Down

0 comments on commit 1c4e734

Please sign in to comment.