mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
22fbc7d02d
* Making directory navigation prettier
* Small improvements
* Rice-box
Former-commit-id: fff23ea4a4aeff16e650571b1e50ac556db55e64 [formerly 1395942367664c8b8cac5181a44089e54002b061] [formerly d9afe630bc365cc227da4f18f76a98fe3f1843d9 [formerly 39a6b7de3c
]]
Former-commit-id: 1d53b93648223d539d24512ea62b0d8ef3e07531 [formerly ee5428b9cd7a1cb3105f5dc42d4dce99584faf66]
Former-commit-id: 2a5352afece16ce936f736cc5a2edcdb208f8671
42 lines
8.2 KiB
Go
42 lines
8.2 KiB
Go
package hugo
|
|
|
|
import (
|
|
"github.com/GeertJohan/go.rice/embedded"
|
|
"time"
|
|
)
|
|
|
|
func init() {
|
|
|
|
// define files
|
|
file2 := &embedded.EmbeddedFile{
|
|
Filename: "hugo.js",
|
|
FileModTime: time.Unix(1501233088, 0),
|
|
Content: string("'use strict';\r\n\r\n(function () {\r\n if (window.plugins === undefined || window.plugins === null) {\r\n window.plugins = []\r\n }\r\n\r\n let regenerate = function (data, url) {\r\n url = data.api.removePrefix(url)\r\n\r\n return new Promise((resolve, reject) => {\r\n let request = new window.XMLHttpRequest()\r\n request.open('POST', `${data.store.state.baseURL}/api/hugo${url}`, true)\r\n request.setRequestHeader('Authorization', `Bearer ${data.store.state.jwt}`)\r\n request.setRequestHeader('Regenerate', 'true')\r\n\r\n request.onload = () => {\r\n if (request.status === 200) {\r\n resolve()\r\n } else {\r\n reject(request.responseText)\r\n }\r\n }\r\n\r\n request.onerror = (error) => reject(error)\r\n request.send()\r\n })\r\n }\r\n\r\n let newArchetype = function (data, url, type) {\r\n url = data.api.removePrefix(url)\r\n\r\n return new Promise((resolve, reject) => {\r\n let request = new window.XMLHttpRequest()\r\n request.open('POST', `${data.store.state.baseURL}/api/hugo${url}`, true)\r\n request.setRequestHeader('Authorization', `Bearer ${data.store.state.jwt}`)\r\n request.setRequestHeader('Archetype', encodeURIComponent(type))\r\n\r\n request.onload = () => {\r\n if (request.status === 200) {\r\n resolve(request.getResponseHeader('Location'))\r\n } else {\r\n reject(request.responseText)\r\n }\r\n }\r\n\r\n request.onerror = (error) => reject(error)\r\n request.send()\r\n })\r\n }\r\n\r\n let schedule = function (data, file, date) {\r\n file = data.api.removePrefix(file)\r\n\r\n return new Promise((resolve, reject) => {\r\n let request = new window.XMLHttpRequest()\r\n request.open('POST', `${data.store.state.baseURL}/api/hugo${file}`, true)\r\n request.setRequestHeader('Authorization', `Bearer ${data.store.state.jwt}`)\r\n request.setRequestHeader('Schedule', date)\r\n\r\n request.onload = () => {\r\n if (request.status === 200) {\r\n resolve(request.getResponseHeader('Location'))\r\n } else {\r\n reject(request.responseText)\r\n }\r\n }\r\n\r\n request.onerror = (error) => reject(error)\r\n request.send()\r\n })\r\n }\r\n\r\n window.plugins.push({\r\n name: 'hugo',\r\n credits: 'With a flavour of <a rel=\"noopener noreferrer\" href=\"https://github.com/hacdias/caddy-hugo\">Hugo</a>.',\r\n header: {\r\n visible: [\r\n {\r\n if: function (data, route) {\r\n return (data.store.state.req.kind === 'editor' &&\r\n !data.store.state.loading &&\r\n data.store.state.req.metadata !== undefined &&\r\n data.store.state.req.metadata !== null &&\r\n data.store.state.user.allowEdit &\r\n data.store.state.user.permissions.allowPublish)\r\n },\r\n click: function (event, data, route) {\r\n event.preventDefault()\r\n document.getElementById('save-button').click()\r\n // TODO: wait for save to finish?\r\n data.buttons.loading('publish')\r\n\r\n regenerate(data, route.path)\r\n .then(() => {\r\n data.buttons.done('publish')\r\n data.store.commit('showSuccess', 'Post published!')\r\n data.store.commit('setReload', true)\r\n })\r\n .catch((error) => {\r\n data.buttons.done('publish')\r\n data.store.commit('showError', error)\r\n })\r\n },\r\n id: 'publish-button',\r\n icon: 'send',\r\n name: 'Publish'\r\n }\r\n ],\r\n hidden: [\r\n {\r\n if: function (data, route) {\r\n return (data.store.state.req.kind === 'editor' &&\r\n !data.store.state.loading &&\r\n data.store.state.req.metadata !== undefined &&\r\n data.store.state.req.metadata !== null &&\r\n data.store.state.user.permissions.allowPublish)\r\n },\r\n click: function (event, data, route) {\r\n document.getElementById('save-button').click()\r\n data.store.commit('showHover', 'schedule')\r\n },\r\n id: 'schedule-button',\r\n icon: 'alarm',\r\n name: 'Schedule'\r\n }\r\n ]\r\n },\r\n sidebar: [\r\n {\r\n click: function (event, data, route) {\r\n data.router.push({ path: '/files/settings' })\r\n },\r\n icon: 'settings',\r\n name: 'Hugo Settings'\r\n },\r\n {\r\n click: function (event, data, route) {\r\n data.store.commit('showHover', 'new-archetype')\r\n },\r\n if: function (data, route) {\r\n return data.store.state.user.allowNew\r\n },\r\n icon: 'merge_type',\r\n name: 'Hugo New'\r\n } /* ,\r\n {\r\n click: function (event, data, route) {\r\n console.log('evt')\r\n },\r\n icon: 'remove_red_eye',\r\n name: 'Preview'\r\n } */\r\n ],\r\n prompts: [\r\n {\r\n name: 'new-archetype',\r\n title: 'New file',\r\n description: 'Create a new post based on an archetype. Your file will be created on content folder.',\r\n inputs: [\r\n {\r\n type: 'text',\r\n name: 'file',\r\n placeholder: 'File name'\r\n },\r\n {\r\n type: 'text',\r\n name: 'archetype',\r\n placeholder: 'Archetype'\r\n }\r\n ],\r\n ok: 'Create',\r\n submit: function (event, data, route) {\r\n event.preventDefault()\r\n\r\n let file = event.currentTarget.querySelector('[name=\"file\"]').value\r\n let type = event.currentTarget.querySelector('[name=\"archetype\"]').value\r\n if (type === '') type = 'default'\r\n\r\n data.store.commit('closeHovers')\r\n\r\n newArchetype(data, '/' + file, type)\r\n .then((url) => {\r\n data.router.push({ path: url })\r\n })\r\n .catch(error => {\r\n data.store.commit('showError', error)\r\n })\r\n }\r\n },\r\n {\r\n name: 'schedule',\r\n title: 'Schedule',\r\n description: 'Pick a date and time to schedule the publication of this post.',\r\n inputs: [\r\n {\r\n type: 'datetime-local',\r\n name: 'date',\r\n placeholder: 'Date'\r\n }\r\n ],\r\n ok: 'Schedule',\r\n submit: function (event, data, route) {\r\n event.preventDefault()\r\n data.buttons.loading('schedule')\r\n\r\n let date = event.currentTarget.querySelector('[name=\"date\"]').value\r\n if (date === '') {\r\n data.buttons.done('schedule')\r\n data.store.commit('showError', 'The date must not be empty.')\r\n return\r\n }\r\n\r\n schedule(data, route.path, date)\r\n .then(() => {\r\n data.buttons.done('schedule')\r\n data.store.commit('showSuccess', 'Post scheduled!')\r\n })\r\n .catch((error) => {\r\n data.buttons.done('schedule')\r\n data.store.commit('showError', error)\r\n })\r\n }\r\n }\r\n ]\r\n })\r\n})()\r\n"),
|
|
}
|
|
|
|
// define dirs
|
|
dir1 := &embedded.EmbeddedDir{
|
|
Filename: "",
|
|
DirModTime: time.Unix(1501233088, 0),
|
|
ChildFiles: []*embedded.EmbeddedFile{
|
|
file2, // "hugo.js"
|
|
|
|
},
|
|
}
|
|
|
|
// link ChildDirs
|
|
dir1.ChildDirs = []*embedded.EmbeddedDir{}
|
|
|
|
// register embeddedBox
|
|
embedded.RegisterEmbeddedBox(`./assets/`, &embedded.EmbeddedBox{
|
|
Name: `./assets/`,
|
|
Time: time.Unix(1501233088, 0),
|
|
Dirs: map[string]*embedded.EmbeddedDir{
|
|
"": dir1,
|
|
},
|
|
Files: map[string]*embedded.EmbeddedFile{
|
|
"hugo.js": file2,
|
|
},
|
|
})
|
|
}
|