add optional prefix to url
This commit is contained in:
@@ -264,7 +264,7 @@
|
||||
<!-- Header -->
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<div class="flex items-center justify-between">
|
||||
<a href="/" class="sidebar-title text-xl font-bold text-white hover:text-blue-300" title="Home">
|
||||
<a href="{{url "/"}}" class="sidebar-title text-xl font-bold text-white hover:text-blue-300" title="Home">
|
||||
{{.app_name}}
|
||||
</a>
|
||||
<div class="flex items-center space-x-2 items-center">
|
||||
@@ -274,14 +274,14 @@
|
||||
</button>
|
||||
{{if .Authenticated}}
|
||||
{{if .IsAdmin}}
|
||||
<a href="/editor/admin" class="text-gray-400 hover:text-white transition-colors" title="Admin">
|
||||
<a href="{{url "/editor/admin"}}" class="text-gray-400 hover:text-white transition-colors" title="Admin">
|
||||
<i class="fas fa-user-shield"></i>
|
||||
</a>
|
||||
{{end}}
|
||||
<a href="/editor/profile" class="text-gray-400 hover:text-white transition-colors" title="Profile">
|
||||
<a href="{{url "/editor/profile"}}" class="text-gray-400 hover:text-white transition-colors" title="Profile">
|
||||
<i class="fas fa-user"></i>
|
||||
</a>
|
||||
<a href="/editor/settings" class="text-gray-400 hover:text-white transition-colors" title="Settings">
|
||||
<a href="{{url "/editor/settings"}}" class="text-gray-400 hover:text-white transition-colors" title="Settings">
|
||||
<i class="fas fa-gear"></i>
|
||||
</a>
|
||||
{{end}}
|
||||
@@ -290,7 +290,7 @@
|
||||
<i class="fas fa-right-from-bracket"></i>
|
||||
</button>
|
||||
{{else}}
|
||||
<a href="/editor/login" class="text-gray-400 hover:text-white transition-colors" title="Login">
|
||||
<a href="{{url "/editor/login"}}" class="text-gray-400 hover:text-white transition-colors" title="Login">
|
||||
<i class="fas fa-right-to-bracket"></i>
|
||||
</a>
|
||||
{{end}}
|
||||
@@ -305,7 +305,7 @@
|
||||
<!-- Navigation -->
|
||||
<div class="sidebar-content px-4 py-4">
|
||||
{{if .Authenticated}}
|
||||
<a href="/editor/create" class="btn-primary text-sm w-full text-center">
|
||||
<a href="{{url "/editor/create"}}" class="btn-primary text-sm w-full text-center">
|
||||
<i class="fas fa-plus mr-2"></i>New Note
|
||||
</a>
|
||||
{{end}}
|
||||
@@ -332,7 +332,7 @@
|
||||
{{range $i, $crumb := .breadcrumbs}}
|
||||
{{if $i}}<i class="fas fa-chevron-right text-gray-500 text-xs"></i>{{end}}
|
||||
{{if $crumb.URL}}
|
||||
<a href="{{$crumb.URL}}" class="text-blue-400 hover:text-blue-300 transition-colors">{{$crumb.Name}}</a>
|
||||
<a href="{{url $crumb.URL}}" class="text-blue-400 hover:text-blue-300 transition-colors">{{$crumb.Name}}</a>
|
||||
{{else}}
|
||||
<span class="text-gray-300">{{$crumb.Name}}</span>
|
||||
{{end}}
|
||||
@@ -401,6 +401,18 @@
|
||||
// Initialize syntax highlighting
|
||||
hljs.highlightAll();
|
||||
|
||||
// Base URL prefix from server
|
||||
window.BASE = '{{base}}';
|
||||
window.prefix = function(p) {
|
||||
var b = window.BASE || '';
|
||||
if (!b) {
|
||||
if (!p) return '';
|
||||
return p[0] === '/' ? p : '/' + p;
|
||||
}
|
||||
if (!p || p === '/') return b + '/';
|
||||
return p[0] === '/' ? (b + p) : (b + '/' + p);
|
||||
};
|
||||
|
||||
// Tree functionality
|
||||
document.addEventListener('click', function(e) {
|
||||
if (e.target.closest('.tree-toggle')) {
|
||||
@@ -423,7 +435,7 @@
|
||||
if (!toggle) return;
|
||||
e.preventDefault();
|
||||
const path = toggle.getAttribute('data-path') || '';
|
||||
const url = '/folder/' + path;
|
||||
const url = window.prefix('/folder/' + path);
|
||||
window.location.href = url;
|
||||
});
|
||||
|
||||
@@ -522,7 +534,7 @@
|
||||
if (hasTree) return; // already populated
|
||||
|
||||
// Fetch tree
|
||||
fetch('/api/tree')
|
||||
fetch(window.prefix('/api/tree'))
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (!data || !Array.isArray(data.children)) return;
|
||||
@@ -554,13 +566,13 @@
|
||||
wrapper.appendChild(toggle);
|
||||
wrapper.appendChild(children);
|
||||
} else {
|
||||
let href = '/view_text/' + (node.path || '');
|
||||
let href = window.prefix('/view_text/' + (node.path || ''));
|
||||
let icon = '📄';
|
||||
if ((node.type || '').toLowerCase() === 'md') {
|
||||
href = '/note/' + (node.path || '');
|
||||
href = window.prefix('/note/' + (node.path || ''));
|
||||
icon = '📝';
|
||||
} else if ((node.type || '').toLowerCase() === 'image') {
|
||||
href = '/serve_attached_image/' + (node.path || '');
|
||||
href = window.prefix('/serve_attached_image/' + (node.path || ''));
|
||||
icon = '🖼️';
|
||||
}
|
||||
const a = document.createElement('a');
|
||||
@@ -636,7 +648,7 @@
|
||||
title.className = 'flex items-center justify-between text-sm text-blue-300 hover:text-blue-200 cursor-pointer';
|
||||
title.innerHTML = `<span><i class="fas ${r.type === 'md' ? 'fa-file-lines' : 'fa-file'} mr-2"></i>${escapeHTML(r.path)}</span>`;
|
||||
title.addEventListener('click', () => {
|
||||
const url = r.path.endsWith('.md') ? `/note/${r.path}` : `/view_text/${r.path}`;
|
||||
const url = r.path.endsWith('.md') ? window.prefix(`/note/${r.path}`) : window.prefix(`/view_text/${r.path}`);
|
||||
// remember query
|
||||
if (searchInput) localStorage.setItem(LS_KEY_QUERY, searchInput.value.trim());
|
||||
window.location.href = url;
|
||||
@@ -661,7 +673,7 @@
|
||||
}
|
||||
try {
|
||||
searchStatus.textContent = 'Searching...';
|
||||
const res = await fetch(`/api/search?q=${encodeURIComponent(query)}`);
|
||||
const res = await fetch(window.prefix(`/api/search?q=${encodeURIComponent(query)}`));
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
localStorage.setItem(LS_KEY_QUERY, query);
|
||||
@@ -696,12 +708,12 @@
|
||||
try {
|
||||
const m = document.cookie.match(/(?:^|; )csrf_token=([^;]+)/);
|
||||
const csrf = m && m[1] ? decodeURIComponent(m[1]) : '';
|
||||
const res = await fetch('/editor/logout', {
|
||||
const res = await fetch(window.prefix('/editor/logout'), {
|
||||
method: 'POST',
|
||||
headers: csrf ? { 'X-CSRF-Token': csrf } : {},
|
||||
});
|
||||
if (res.ok) {
|
||||
window.location.href = '/editor/login';
|
||||
window.location.href = window.prefix('/editor/login');
|
||||
} else {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
showNotification('Logout failed: ' + (data.error || res.statusText), 'error');
|
||||
@@ -762,17 +774,17 @@
|
||||
</div>
|
||||
{{else}}
|
||||
{{if eq .node.Type "md"}}
|
||||
<a href="/note/{{.node.Path}}" class="sidebar-item {{if eq .current_note .node.Path}}active{{end}}">
|
||||
<a href="{{url (print "/note/" .node.Path)}}" class="sidebar-item {{if eq .current_note .node.Path}}active{{end}}">
|
||||
<span class="mr-2">📝</span>
|
||||
<span>{{.node.Name}}</span>
|
||||
</a>
|
||||
{{else if eq .node.Type "image"}}
|
||||
<a href="/serve_attached_image/{{.node.Path}}" target="_blank" class="sidebar-item" title="View image in new tab">
|
||||
<a href="{{url (print "/serve_attached_image/" .node.Path)}}" target="_blank" class="sidebar-item" title="View image in new tab">
|
||||
<span class="mr-2">🖼️</span>
|
||||
<span>{{.node.Name}}</span>
|
||||
</a>
|
||||
{{else}}
|
||||
<a href="/view_text/{{.node.Path}}" class="sidebar-item">
|
||||
<a href="{{url (print "/view_text/" .node.Path)}}" class="sidebar-item">
|
||||
<span class="mr-2">📄</span>
|
||||
<span>{{.node.Name}}</span>
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user