Skip to content

Commit c4ec3c1

Browse files
committed
html2text function, simplified sanitization.
1 parent 13799cb commit c4ec3c1

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/css/fraidy.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ div.intro {
296296

297297
ul {
298298
white-space: nowrap;
299+
margin-top: 4px;
299300

300301
@include themed() {
301302
border-bottom: solid 4px t('border');

src/js/storage.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// instance to pull down feeds and operate independently. This allows the
1717
// instance to run alone, with no syncing, should the user want it that way.
1818
//
19-
import { followTitle, house, getIndexById, Importances,
19+
import { followTitle, house, html2text, getIndexById, Importances,
2020
urlToFeed, urlToID, urlToNormal } from './util'
2121
import u from '@kickscondor/umbrellajs'
2222

@@ -292,8 +292,8 @@ module.exports = {
292292
}
293293

294294
index.title = (ident === 0 && item.title) || item.text
295-
if (!index.title)
296-
index.title = u("<div>" + item.html).text()
295+
if (!index.title && item.html)
296+
index.title = html2text(item.html)
297297
if (!index.title && item.publishedAt)
298298
index.title = item.publishedAt.toLocaleString()
299299
if (!index.title && ident !== 0)
@@ -314,6 +314,10 @@ module.exports = {
314314
if (feed.status instanceof Array) {
315315
for (let item of feed.status) {
316316
item.updatedAt = item.updatedAt || item.publishedAt
317+
if (!item.text && item.html) {
318+
item.text = html2text(item.html)
319+
delete item.html
320+
}
317321
}
318322
}
319323

src/js/util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const normalizeUrl = require('normalize-url')
2+
import u from '@kickscondor/umbrellajs'
23

34
export const house = "\u{1f3e0}"
45

@@ -44,6 +45,12 @@ export function getMaxIndex (index) {
4445
return Math.max(...vals)
4546
}
4647

48+
export function html2text (html) {
49+
if (html.replace)
50+
html = html.replace(/[a-z]+:\/\//g, ' ')
51+
return u("<div>" + html).text()
52+
}
53+
4754
export function urlToFeed(abs, href) {
4855
return normalizeUrl(url.resolve(abs, href), {stripWWW: false, stripHash: true, removeTrailingSlash: false})
4956
}

src/js/view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { followTitle, getIndexById, house, Importances } from './util'
1+
import { followTitle, html2text, getIndexById, house, Importances } from './util'
22
import { h } from 'hyperapp'
33
import { jsonDateParser } from "json-date-parser"
44
import { Link, Route, Switch } from '@kickscondor/router'
@@ -376,7 +376,7 @@ const ListFollow = ({ location, match }) => ({follows}, actions) => {
376376
{follow.status instanceof Array && follow.status.map(st =>
377377
<a class={`status status-${st.type}`} oncreate={ToggleHover} href={st.url || follow.url}
378378
>{st.type === 'live' ? <span>&#x25cf; LIVE</span> : <span>&#x1f5d2;</span>}
379-
<div>{st.title || st.text || <span innerHTML={st.html} />}
379+
<div>{st.title || st.text || html2text(st.html)}
380380
{st[sortPosts] && <span class="ago">{timeAgo(st[sortPosts], now)}</span>}</div>
381381
</a>)}
382382
{ago && <span class="latest">{ago}</span>}

0 commit comments

Comments
 (0)