Skip to content
Permalink
Browse files

Closes #22.

  • Loading branch information
kickscondor committed Nov 14, 2019
1 parent d3bd66d commit 39c2612c66dcee41e85c8d172d41626836c55276
Showing with 20 additions and 11 deletions.
  1. +2 −2 src/js/follows.js
  2. +17 −8 src/js/storage.js
  3. +1 −1 src/js/view.js
@@ -99,12 +99,12 @@ export default ({
//
// Import follows from OPML.
//
importFrom: (e, format) => ({local}, {location}) => {
importFrom: (e) => ({local}, {location}) => {
let f = e.target.files[0]
if (f) {
let r = new FileReader()
r.onload = async function (o) {
let contents = o.target.result
let contents = o.target.result, format = e.target.name
await local.command("importFrom", {format, contents})
if (window.location.pathname === "/settings.html")
window.close()
@@ -232,29 +232,38 @@ module.exports = {
//
// Import follows from the OPML - everything that's missing.
//
let follows = []
let follows = [], parents = []
let xml = sax.createStream(false, {lowercasetags: true}), currentTag = null
xml.on('opentag', node => {
if (node.name == 'outline') {
let url = node.attributes.xmlurl || node.attributes.htmlurl
if (url) {
let tags = [], match = null, importance = 0
if (node.attributes.category) {
tags = node.attributes.category.split(',').filter(tag => {
if ((match = tag.match(/^importance\/(\d+)$/)) !== null) {
importance = Number(match[1])
return false
}
return true
})
tags = node.attributes.category.split(',')
}
tags = tags.concat(parents).filter(tag => {
if ((match = tag.match(/^importance\/(\d+)$/)) !== null) {
importance = Number(match[1])
return false
}
return true
})

if (tags.length == 0)
tags = null

follows.push({url, tags, importance, title: node.attributes.title,
editedAt: new Date(node.attributes.created)})
}

if (!node.isSelfClosing) {
parents.push(node.attributes.text)
}
}
}).on('closetag', name => {
if (name == 'outline') {
parents.pop()
}
})
xml.write(data.contents)
@@ -286,7 +286,7 @@ const ChangeSettings = ({ match, setup }) => (_, {follows}) => {
return <div id="settings">
<form onsubmit={e => e.preventDefault()}>
<input type="file" id="fileImp" style="display: none" name=""
onchange={e => follows.importFrom(e, e.target.name)} />
onchange={e => follows.importFrom(e)} />
<h3>Import / Export</h3>
<div>
<p><strong>JSON:</strong>

0 comments on commit 39c2612

Please sign in to comment.
You can’t perform that action at this time.