|
4 | 4 | ** The dokeili system allows the user to edit a document including anotations |
5 | 5 | ** review. It does not use turtle, but RDF/a |
6 | 6 | */ |
| 7 | +/* global alert */ |
| 8 | + |
7 | 9 | const UI = require('solid-ui') |
8 | 10 | const mime = require('mime-types') |
9 | 11 |
|
@@ -74,32 +76,25 @@ module.exports = { |
74 | 76 | newPaneOptions.newBase = uri |
75 | 77 | } |
76 | 78 | newInstance = kb.sym(uri) |
77 | | - newPaneOptions.newInstance = newInstance |
78 | 79 | } |
79 | 80 |
|
80 | 81 | var contentType = mime.lookup(newInstance.uri) |
81 | 82 | 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') |
85 | 84 | } |
| 85 | + newPaneOptions.newInstance = newInstance // Save for creation system |
86 | 86 |
|
87 | 87 | 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 | | - */ |
100 | 88 |
|
| 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, '&').replace(/</g, '<').replace(/>/g, '>') |
| 93 | + htmlContents = htmlContents.replace('<title>', '<title>' + encodedTitle) |
| 94 | + htmlContents = htmlContents.replace('</article>', '<h1>' + encodedTitle + '</h1></article>') |
| 95 | + console.log('@@ New HTML for Dok:' + htmlContents) |
101 | 96 | 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' }) |
103 | 98 | .then(function () { |
104 | 99 | console.log('new Dokieli document created at ' + newPaneOptions.newInstance) |
105 | 100 | resolve(newPaneOptions) |
@@ -140,7 +135,7 @@ module.exports = { |
140 | 135 | iframe.setAttribute('style', 'resize = both; height: 40em; width:40em;') // @@ improve guess |
141 | 136 | // iframe.setAttribute('height', '480') |
142 | 137 | // iframe.setAttribute('width', '640') |
143 | | - var tr = myDocument.createElement('TR') |
| 138 | + var tr = myDocument.createElement('tr') |
144 | 139 | tr.appendChild(iframe) |
145 | 140 | div.appendChild(tr) |
146 | 141 | return div |
|
0 commit comments