Comparing version 0.2.0 to 0.3.0
@@ -0,1 +1,7 @@ | ||
# v0.3.0 | ||
Adds: | ||
- Custom Output Format | ||
- Custom HTML templates | ||
# v0.2.0 | ||
@@ -2,0 +8,0 @@ |
@@ -5,3 +5,3 @@ ![header](./assets/Favicon.png) | ||
# Creamcrop <small>v0.2.0</small> | ||
# Creamcrop <small>v0.3.0</small> | ||
@@ -8,0 +8,0 @@ > A cream-of-the-crop, top-of-the-top, slice-and-chop, absolutely minimalist news getter |
@@ -19,3 +19,4 @@ > Configuration for the package | ||
"feed2_url", | ||
"feed3_url" | ||
"feed3_url", | ||
... | ||
] | ||
@@ -25,8 +26,10 @@ } | ||
Later on, more parameters will be added. | ||
Currently, `feeds` is the only required parameter. | ||
## Valid parameters | ||
| Parameter | Description | Default | | ||
| --------- | ----------- | ------- | | ||
| `feeds` | Array of feeds to parse | No default. **Required**. | | ||
| Parameter | Description | Default | Values | | ||
| --------- | ----------- | ------- | ------ | | ||
| `feeds` | Array of feeds to parse | No default. **Required**. | An array of URLs to feeds | | ||
| `format` | The format of the output. Each value should be surrounded by `%`. | `<a href="%link%">%item%</a> from <a href="%feedlink%">%feed%</a>` | `%feed%`- The name of the RSS feed the item is in. <br> `%feedlink%` - The RSS feed's link that the item is in. <br> `%item%` - The name of the RSS feed Item. <br> `%itemlink%` Link to the item. | | ||
| `custom` | A custom HTML template. Inside the HTML, use `%feed%`, which will be replaced by the content of the feed. | A basic HTML page. | The relative path to the HTML template file | |
@@ -79,3 +79,3 @@ > Learn the fundamentals of creamcrop | ||
Qlabs (@Quantalabs) | ||
0.2.0 | ||
0.3.0 | ||
``` | ||
@@ -121,3 +121,3 @@ | ||
$ cream --version | ||
0.2.0 | ||
0.3.0 | ||
``` |
{ | ||
"name": "creamcrop", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A cream-of-the-crop, top-of-the-top, slice-and-chop, absolutely minimalist news getter.", | ||
@@ -36,3 +36,2 @@ "main": "src/index.js", | ||
"boxen": "^5.0.1", | ||
"open": "^8.2.1", | ||
"rss-parser": "^3.12.0", | ||
@@ -39,0 +38,0 @@ "update-notifier": "^5.1.0", |
@@ -11,3 +11,3 @@ const http = require('http'); | ||
async function serve(dir) { | ||
if (fs.existsSync(dir+'/.creamcroprc') || fs.existsSync(dir+'.creamcroprc.json')) { | ||
if (fs.existsSync(dir+'/.creamcroprc') || fs.existsSync(dir+'.creamcroprc')) { | ||
console.log('Found config file, generating website...') | ||
@@ -36,7 +36,46 @@ } | ||
const requestListener = function (req, res) { | ||
res.writeHead(200, { | ||
'Content-Type': 'text/html' | ||
}); | ||
const html = ` | ||
function format(title, link, feedlink, feed) { | ||
if (config.format !== undefined) { | ||
var format = config.format | ||
format = format.replace(/%title%/g, title); | ||
format = format.replace(/%link%/g, link); | ||
format = format.replace(/%feed%/g, feed); | ||
format = format.replace(/%feedlink%/g, feedlink); | ||
return format; | ||
} | ||
else { | ||
return `<a href="${link}">${title}</a> from <a href="${feedlink}">${feed}</a>`; | ||
} | ||
} | ||
let html = '' | ||
if (config.custom !== undefined) { | ||
console.log('\nParsing custom HTML...'); | ||
let customconf = '' | ||
if (fs.existsSync(dir+config.custom)) { | ||
customconf = fs.readFileSync(dir+config.custom, {encoding:'utf8', flag:'r'}); | ||
} | ||
else if (fs.existsSync(dir+'/'+config.custom)) { | ||
customconf = fs.readFileSync(dir+'/'+config.custom, {encoding:'utf8', flag:'r'}); | ||
} | ||
else { | ||
console.log('Custom file not found: ' + dir+config.custom); | ||
process.exit(1); | ||
} | ||
console.log('\nParsing RSS feed(s)...'); | ||
customconf = customconf.replace(/%feed%/g, feed.items.map(item => ` | ||
<li> | ||
${format(item.title, item.link, item.feedlink, item.feed)} | ||
</li> | ||
`).join('\n')); | ||
html = customconf | ||
} | ||
else { | ||
console.log('\nParsing RSS feed(s)...\n'); | ||
html = ` | ||
<!DOCTYPE html> | ||
@@ -53,3 +92,3 @@ <html> | ||
<li> | ||
<a href="${item.link}">${item.title}</a> from <a href="${item.feedlink}">${item.feed}</a> | ||
${format(item.title, item.link, item.feedlink, item.feed)} | ||
</li> | ||
@@ -61,2 +100,8 @@ `).join('\n')} | ||
`; | ||
} | ||
const requestListener = function (req, res) { | ||
res.writeHead(200, { | ||
'Content-Type': 'text/html' | ||
}); | ||
res.end(html); | ||
@@ -67,5 +112,5 @@ } | ||
server.listen(8080); | ||
console.log('Server running at http://localhost:8080') | ||
console.log('\n\nServer running at http://localhost:8080') | ||
} | ||
exports.serve = serve |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
141171
4
238
- Removedopen@^8.2.1
- Removeddefine-lazy-prop@2.0.0(transitive)
- Removedis-docker@2.2.1(transitive)
- Removedis-wsl@2.2.0(transitive)
- Removedopen@8.4.2(transitive)