mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 14:03:42 +00:00
fix: fix templates
This commit is contained in:
parent
1f7f094282
commit
5d2a6fce30
@ -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
|
||||
|
@ -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