Skip to content

Commit

Permalink
Refactor build script and fix turndown
Browse files Browse the repository at this point in the history
  • Loading branch information
tztsai committed Nov 12, 2024
1 parent 6de4988 commit 44f7552
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions build/turndown/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
cd "$(dirname "$0")"

# before
npm ci 2> /dev/null || npm i
# npm ci 2> /dev/null || npm i

# # turndown.min.js
npx rollup --config rollup.mjs --input turndown.mjs --file turndown.js
# npx rollup --config rollup.mjs --input turndown.mjs --file turndown.js

# FIXIT: replace domino require with import
# awk '/var domino = require('\''@mixmark-io\/domino'\'');/ {
Expand All @@ -21,4 +21,4 @@ npx rollup --config rollup.mjs --input turndown.mjs --file turndown.js
npx terser --compress --mangle -- turndown.js > ../../vendor/turndown.min.js

# after
rm -rf node_modules/
# rm -rf node_modules/
2 changes: 2 additions & 0 deletions build/turndown/turndown.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
},

replacement: function (content, node) {
content = content.replace(/\n/gm, '\t');
var href = node.getAttribute('href');
if (href) href = href.replace(/([()])/g, '\\$1');
var title = cleanAttribute(node.getAttribute('title'));
Expand All @@ -256,6 +257,7 @@
if (title) title = ' "' + title + '"';
var replacement;
var reference;
content = content.replace(/\n/gm, '\t');

switch (options.linkReferenceStyle) {
case 'collapsed':
Expand Down
12 changes: 9 additions & 3 deletions content/mdwise.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
function cleanHtml() {
if (main = document.querySelector('main')) {
document.body.innerHTML = main.innerHTML;
}
if (articles = document.querySelectorAll('article')) {
document.body.innerHTML = '';
articles.forEach(e => document.body.appendChild(e));
} else if (main = document.querySelector('main')) {
document.body.innerHTML = main.innerHTML;
for (e of articles) {
if (e.textContent.trim().length > 20) {
document.body.appendChild(e);
}
}
}
document.querySelectorAll(
'link, style, script, meta, noscript, header, nav, span, footer, figure, table'
).forEach(e => e.remove());

}

async function generateSummaries(html) {
Expand Down
13 changes: 3 additions & 10 deletions manifest.chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"manifest_version": 3,
"name" : "MDwise Page Reader",
"version" : "1.0",
"description" : "Dark Mode • Themes • Autoreload • Mermaid Diagrams • MathJax • ToC • Syntax Highlighting",
"description" : "MDwise Page Reader is a Chrome extension that utilizes AI to provide interactive summaries and Q&A for web pages. It allows users to convert web pages into interactive markdown format, making it easier to read and navigate through the content.",

"homepage_url": "https://chromewebstore.google.com/detail/markdown-viewer/ckkdlimhmcjmikdlpkmbgfkaikojcbjk",


"icons": {
"96" : "/icons/default/favicon-96x96.png"
},
Expand Down Expand Up @@ -47,15 +46,13 @@
"storage",
"scripting",
"contextMenus",
"tabs",
"commands"
],

"commands": {
"convert-to-markdown": {
"md-wise": {
"suggested_key": {
"default": "Ctrl+M",
"mac": "MacCtrl+M"
"default": "Ctrl+Alt+A"
},
"description": "Convert Web Page to Interactive Markdown",
"global": true
Expand All @@ -68,9 +65,5 @@

"optional_host_permissions": [
"*://*/"
],

"optional_permissions": [
"webRequest"
]
}
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name" : "MDwise Page Reader",
"version" : "1.0",
"description" : "Dark Mode • Themes • Autoreload • Mermaid Diagrams • MathJax • ToC • Syntax Highlighting",
"description" : "MDwise Page Reader is a Chrome extension that utilizes AI to provide interactive summaries and Q&A for web pages. It allows users to convert web pages into interactive markdown format, making it easier to read and navigate through the content.",

"homepage_url": "https://chromewebstore.google.com/detail/markdown-viewer/ckkdlimhmcjmikdlpkmbgfkaikojcbjk",

Expand Down Expand Up @@ -52,7 +52,7 @@
"commands": {
"md-wise": {
"suggested_key": {
"default": "Ctrl+M"
"default": "Ctrl+Alt+A"
},
"description": "Convert Web Page to Interactive Markdown",
"global": true
Expand Down

0 comments on commit 44f7552

Please sign in to comment.