fix: fix templates

This commit is contained in:
KernelDeimos 2024-07-22 17:10:58 -04:00
parent 1f7f094282
commit 5d2a6fce30
2 changed files with 25 additions and 5 deletions

View File

@ -869,12 +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]
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);
console.log(extension)
if(extension == "txt") extension = "text"
// TODO: should use path join utility
const path =
baseRoute + "/" +
hasTemplateFolder.name + '/' +
element.name;
const itemStructure = {
path,
html: `${extension.toUpperCase()} ${name}`,
extension:extension,
name: element.name

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