intermediate
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
# Node.js
|
||||
node_modules/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Logs
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids/
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Compiled output
|
||||
build/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm/
|
||||
+1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
+4149
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "readability",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"remove-markdown": "^0.5.5",
|
||||
"turndown": "^7.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.26.0",
|
||||
"@babel/preset-env": "^7.26.0",
|
||||
"babel-loader": "^9.2.1",
|
||||
"clean-webpack-plugin": "^4.0.0",
|
||||
"terser-webpack-plugin": "^5.3.10",
|
||||
"webpack": "^5.96.1",
|
||||
"webpack-bundle-analyzer": "^4.10.2",
|
||||
"webpack-cli": "^5.1.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Readability } from '@mozilla/readability';
|
||||
import TurndownService from 'turndown';
|
||||
|
||||
const removeMarkdown = require('remove-markdown');
|
||||
|
||||
const turndownService = new TurndownService();
|
||||
|
||||
function parseReaderable(document, options) {
|
||||
const clonedDoc = document.cloneNode(true);
|
||||
|
||||
const fullMarkdown = turndownService.turndown(clonedDoc.body.innerHTML);
|
||||
|
||||
let response = {
|
||||
fullContentMarkdown: fullMarkdown,
|
||||
fullContentPlain: removeMarkdown(fullMarkdown),
|
||||
}
|
||||
|
||||
const reader = new Readability(clonedDoc, options);
|
||||
const article = reader.parse();
|
||||
|
||||
if(article != null) {
|
||||
const extractedMarkdown = turndownService.turndown(article.content);
|
||||
|
||||
response = {
|
||||
...response,
|
||||
extractedContentMarkdown: extractedMarkdown,
|
||||
extractedContentPlain: removeMarkdown(extractedMarkdown)
|
||||
};
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
window.parseReaderable = parseReaderable;
|
||||
export { parseReaderable };
|
||||
@@ -0,0 +1,49 @@
|
||||
const path = require('path');
|
||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
entry: './src/index.js',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: 'readability.min.js',
|
||||
library: 'ReadabilityBundle',
|
||||
libraryTarget: 'umd',
|
||||
globalObject: 'this'
|
||||
},
|
||||
mode: 'production',
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: ['@babel/preset-env']
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
optimization: {
|
||||
minimize: true,
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
extractComments: false
|
||||
})
|
||||
],
|
||||
usedExports: true,
|
||||
sideEffects: true
|
||||
},
|
||||
plugins: [
|
||||
new CleanWebpackPlugin(),
|
||||
new BundleAnalyzerPlugin({
|
||||
analyzerMode: 'static',
|
||||
openAnalyzer: false,
|
||||
generateStatsFile: true,
|
||||
statsOptions: { source: false }
|
||||
})
|
||||
]
|
||||
};
|
||||
Reference in New Issue
Block a user