Skip to content

Commit 5d2a6fc

Browse files
committed
fix: fix templates
1 parent 1f7f094 commit 5d2a6fc

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/gui/src/helpers.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -869,12 +869,26 @@ window.available_templates = async () => {
869869

870870
hasTemplateFiles.forEach(element => {
871871
console.log(element)
872-
const elementInformation = element.name.split(".")
873-
const name = elementInformation[0]
874-
let extension = elementInformation[1]
872+
873+
const extIndex = element.name.lastIndexOf('.');
874+
const name = extIndex === -1
875+
? element.name
876+
: element.name.slice(0, extIndex);
877+
let extension = extIndex === -1
878+
? ''
879+
: element.name.slice(extIndex + 1);
880+
875881
console.log(extension)
876882
if(extension == "txt") extension = "text"
883+
884+
// TODO: should use path join utility
885+
const path =
886+
baseRoute + "/" +
887+
hasTemplateFolder.name + '/' +
888+
element.name;
889+
877890
const itemStructure = {
891+
path,
878892
html: `${extension.toUpperCase()} ${name}`,
879893
extension:extension,
880894
name: element.name

src/gui/src/helpers/new_context_menu_item.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@ const new_context_menu_item = function(dirname, append_to_element){
8484
items: window.file_templates.map(template => ({
8585
html: template.html,
8686
icon: `<img src="${html_encode(window.icons[`file-${template.extension}.svg`])}" class="ctx-item-icon">`,
87-
onClick: function() {
88-
window.create_file({dirname: dirname, append_to_element: append_to_element, name: template.name});
87+
onClick: async function () {
88+
const content = await puter.fs.read(template.path);
89+
window.create_file({
90+
dirname: dirname,
91+
append_to_element: append_to_element,
92+
name: template.name,
93+
content,
94+
});
8995
}
9096
}))
9197
});

0 commit comments

Comments
 (0)