Fix page creation
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
function newPage() {
|
||||
const name = prompt('New page name:');
|
||||
if (!name || !name.trim()) return;
|
||||
const slug = name.trim().replace(/\s+/g, '-');
|
||||
window.location.href = window.location.pathname + slug + '/?edit';
|
||||
}
|
||||
|
||||
(function () {
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (!e.altKey || !e.shiftKey) return;
|
||||
@@ -5,7 +12,11 @@
|
||||
case 'E':
|
||||
e.preventDefault();
|
||||
window.location.href = window.location.pathname + '?edit';
|
||||
break;
|
||||
break;
|
||||
case 'N':
|
||||
e.preventDefault();
|
||||
newPage();
|
||||
break;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
<a class="btn-cancel" href="{{.PostURL}}">CANCEL</a>
|
||||
<button class="btn-save" type="submit" form="edit-form" data-action="save" data-key="S" title="Save (S)">SAVE</button>
|
||||
{{else if .CanEdit}}
|
||||
<a class="edit-btn" href="?edit" title="Edit (Alt+Shift+E)">EDIT</a>
|
||||
<button class="new-btn" onclick="newPage()" title="New page (N)">NEW</button>
|
||||
<a class="edit-btn" href="?edit" title="Edit page (E)">EDIT</a>
|
||||
{{end}}
|
||||
</header>
|
||||
<main>
|
||||
|
||||
@@ -102,6 +102,25 @@ header {
|
||||
color: #ffd54f;
|
||||
}
|
||||
|
||||
.new-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #ffb300;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.new-btn::before {
|
||||
content: "[";
|
||||
}
|
||||
.new-btn::after {
|
||||
content: "]";
|
||||
}
|
||||
.new-btn:hover {
|
||||
color: #ffd54f;
|
||||
}
|
||||
|
||||
/* === Main === */
|
||||
main {
|
||||
max-width: 860px;
|
||||
@@ -313,6 +332,7 @@ textarea:focus {
|
||||
color: #ffb300;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
text-shadow: inherit;
|
||||
padding: 0;
|
||||
}
|
||||
.btn-save::before {
|
||||
@@ -330,6 +350,7 @@ textarea:focus {
|
||||
border: none;
|
||||
color: #ffb300;
|
||||
font: inherit;
|
||||
text-shadow: inherit;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
text-decoration: none;
|
||||
|
||||
10
main.go
10
main.go
@@ -86,7 +86,15 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
info, err := os.Stat(fsPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) && strings.HasSuffix(r.URL.Path, "/") {
|
||||
if os.IsNotExist(err) {
|
||||
// Non-existent path: redirect GETs to the canonical slash form so
|
||||
// the browser URL is consistent, then serve an empty folder page.
|
||||
// POSTs must not be redirected — the form action has no trailing
|
||||
// slash (path.Clean strips it) and the content would be lost.
|
||||
if !strings.HasSuffix(r.URL.Path, "/") && r.Method != http.MethodPost {
|
||||
http.Redirect(w, r, r.URL.Path+"/", http.StatusMovedPermanently)
|
||||
return
|
||||
}
|
||||
h.serveDir(w, r, urlPath, fsPath)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user