mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 14:03:42 +00:00
Merge pull request #628 from HeyPuter/eric/fix-templates
Write contents from template when creating a file from a tempalte
This commit is contained in:
commit
f8b39630ab
@ -869,17 +869,26 @@ window.available_templates = async () => {
|
||||
|
||||
hasTemplateFiles.forEach(element => {
|
||||
console.log(element)
|
||||
const elementInformation = element.name.split(".")
|
||||
const name = elementInformation[0]
|
||||
let extension = elementInformation[1]
|
||||
console.log(extension)
|
||||
|
||||
const extIndex = element.name.lastIndexOf('.');
|
||||
const name = extIndex === -1
|
||||
? element.name
|
||||
: element.name.slice(0, extIndex);
|
||||
let extension = extIndex === -1
|
||||
? ''
|
||||
: element.name.slice(extIndex + 1);
|
||||
|
||||
if(extension == "txt") extension = "text"
|
||||
|
||||
const _path = path.join( baseRoute, hasTemplateFolder.name, element.name);
|
||||
|
||||
console.log(_path)
|
||||
const itemStructure = {
|
||||
path: _path,
|
||||
html: `${extension.toUpperCase()} ${name}`,
|
||||
extension:extension,
|
||||
name: element.name
|
||||
}
|
||||
console.log(extension)
|
||||
result.push(itemStructure)
|
||||
});
|
||||
|
||||
|
@ -84,8 +84,14 @@ const new_context_menu_item = function(dirname, append_to_element){
|
||||
items: window.file_templates.map(template => ({
|
||||
html: template.html,
|
||||
icon: `<img src="${html_encode(window.icons[`file-${template.extension}.svg`])}" class="ctx-item-icon">`,
|
||||
onClick: function() {
|
||||
window.create_file({dirname: dirname, append_to_element: append_to_element, name: template.name});
|
||||
onClick: async function () {
|
||||
const content = await puter.fs.read(template.path);
|
||||
window.create_file({
|
||||
dirname: dirname,
|
||||
append_to_element: append_to_element,
|
||||
name: template.name,
|
||||
content,
|
||||
});
|
||||
}
|
||||
}))
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user