Skip to content

Commit c508b58

Browse files
author
Tim Berners-Lee
committed
Fix new dokieli document creation in data browser
1 parent fc3deec commit c508b58

1 file changed

Lines changed: 13 additions & 18 deletions

File tree

dokieli/dokieliPane.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
** The dokeili system allows the user to edit a document including anotations
55
** review. It does not use turtle, but RDF/a
66
*/
7+
/* global alert */
8+
79
const UI = require('solid-ui')
810
const mime = require('mime-types')
911

@@ -74,32 +76,25 @@ module.exports = {
7476
newPaneOptions.newBase = uri
7577
}
7678
newInstance = kb.sym(uri)
77-
newPaneOptions.newInstance = newInstance
7879
}
7980

8081
var contentType = mime.lookup(newInstance.uri)
8182
if (!contentType || !contentType.includes('html')) {
82-
let msg = 'A new text file has to have an file extension like .html .htm etc.'
83-
alert(msg)
84-
throw new Error(msg)
83+
newInstance = $rdf.sym(newInstance.uri + '.html')
8584
}
85+
newPaneOptions.newInstance = newInstance // Save for creation system
8686

8787
console.log('New dokieli will make: ' + newInstance)
88-
/*
89-
return new Promise(function(resolve, reject){
90-
kb.fetcher.webCopy(DOKIELI_TEMPLATE_URI, newInstance.uri, 'text/html')
91-
.then(function(){
92-
console.log('new Dokieli document created at ' + newPaneOptions.newInstance)
93-
resolve(newPaneOptions)
94-
}).catch(function(err){
95-
console.log('Error creating dokelili dok at ' +
96-
newPaneOptions.newInstance + ': ' + err )
97-
})
98-
})
99-
*/
10088

89+
var htmlContents = DOKIELI_TEMPLATE
90+
var filename = newInstance.uri.split('/').slice(-1)[0]
91+
filename = decodeURIComponent(filename.split('.')[0])
92+
const encodedTitle = filename.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
93+
htmlContents = htmlContents.replace('<title>', '<title>' + encodedTitle)
94+
htmlContents = htmlContents.replace('</article>', '<h1>' + encodedTitle + '</h1></article>')
95+
console.log('@@ New HTML for Dok:' + htmlContents)
10196
return new Promise(function (resolve, reject) {
102-
kb.fetcher.webOperation('PUT', newInstance.uri, { data: DOKIELI_TEMPLATE, contentType: 'text/html' })
97+
kb.fetcher.webOperation('PUT', newInstance.uri, { data: htmlContents, contentType: 'text/html' })
10398
.then(function () {
10499
console.log('new Dokieli document created at ' + newPaneOptions.newInstance)
105100
resolve(newPaneOptions)
@@ -140,7 +135,7 @@ module.exports = {
140135
iframe.setAttribute('style', 'resize = both; height: 40em; width:40em;') // @@ improve guess
141136
// iframe.setAttribute('height', '480')
142137
// iframe.setAttribute('width', '640')
143-
var tr = myDocument.createElement('TR')
138+
var tr = myDocument.createElement('tr')
144139
tr.appendChild(iframe)
145140
div.appendChild(tr)
146141
return div

0 commit comments

Comments
 (0)