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:
Nariman Jelveh 2024-07-22 16:53:01 -07:00 committed by GitHub
commit f8b39630ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 7 deletions

View File

@ -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)
});

View File

@ -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,
});
}
}))
});