i think this might work

This commit is contained in:
2025-07-27 17:13:21 +02:00
parent e3d8ba1017
commit c3c74bb21f
18 changed files with 123 additions and 104 deletions

View File

@@ -23,6 +23,7 @@ import matter from 'gray-matter';
import dynamicImport from 'next/dynamic';
import { Theme } from 'emoji-picker-react';
import '../highlight-github.css';
import { withBaseUrl } from '@/lib/baseUrl';
const MonacoEditor = dynamicImport(() => import('./MonacoEditor'), { ssr: false });
// Import monaco-vim only on client side
let initVimMode: any = null;
@@ -162,7 +163,7 @@ export default function AdminPage() {
useEffect(() => {
// Check if docker is used
fetch('/api/admin/docker')
fetch(withBaseUrl('/api/admin/docker'))
.then(res => res.json())
.then(data => setIsDocker(!!data.docker))
.catch(() => setIsDocker(false));
@@ -170,7 +171,7 @@ export default function AdminPage() {
const loadContent = async () => {
try {
const response = await fetch('/api/posts');
const response = await fetch(withBaseUrl('/api/posts'));
const data = await response.json();
setNodes(data);
} catch (error) {
@@ -189,7 +190,7 @@ export default function AdminPage() {
return;
}
// Check password via API
const res = await fetch('/api/admin/password', {
const res = await fetch(withBaseUrl('/api/admin/password'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: pass, mode: 'login' }),
@@ -213,7 +214,7 @@ export default function AdminPage() {
const handleCreatePost = async (e: React.FormEvent) => {
e.preventDefault();
try {
const response = await fetch('/api/admin/posts', {
const response = await fetch(withBaseUrl('/api/admin/posts'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -251,7 +252,7 @@ export default function AdminPage() {
}
try {
const response = await fetch('/api/admin/folders', {
const response = await fetch(withBaseUrl('/api/admin/folders'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -347,7 +348,7 @@ export default function AdminPage() {
formData.append('file', file);
formData.append('path', currentPath.join('/'));
const response = await fetch('/api/admin/upload', {
const response = await fetch(withBaseUrl('/api/admin/upload'), {
method: 'POST',
body: formData,
});
@@ -381,7 +382,7 @@ export default function AdminPage() {
type: deleteConfirm.item.type
});
const response = await fetch('/api/admin/delete', {
const response = await fetch(withBaseUrl('/api/admin/delete'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -414,7 +415,7 @@ export default function AdminPage() {
? prev.filter((s) => s !== slug)
: [slug, ...prev];
// Update pinned.json on the server
fetch('/api/admin/posts', {
fetch(withBaseUrl('/api/admin/posts'), {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ pinned: newPinned }),
@@ -453,7 +454,7 @@ export default function AdminPage() {
return;
}
// Check old password
const res = await fetch('/api/admin/password', {
const res = await fetch(withBaseUrl('/api/admin/password'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: changePwOld, mode: 'login' }),
@@ -464,7 +465,7 @@ export default function AdminPage() {
return;
}
// Set new password
const res2 = await fetch('/api/admin/password', {
const res2 = await fetch(withBaseUrl('/api/admin/password'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: changePwNew }),
@@ -484,7 +485,7 @@ export default function AdminPage() {
// Function to load a post's raw markdown
const loadPostRaw = async (slug: string, folderPath: string) => {
const params = new URLSearchParams({ slug, path: folderPath });
const res = await fetch(`/api/admin/posts/raw?${params.toString()}`);
const res = await fetch(withBaseUrl(`/api/admin/posts/raw?${params.toString()}`));
if (!res.ok) {
alert('Error loading post');
return;
@@ -516,7 +517,7 @@ export default function AdminPage() {
summary: newPost.summary,
author: process.env.NEXT_PUBLIC_BLOG_OWNER + "'s" || 'Anonymous',
});
const response = await fetch('/api/admin/posts', {
const response = await fetch(withBaseUrl('/api/admin/posts'), {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -606,9 +607,9 @@ export default function AdminPage() {
}
closeModal();
if (choice === 'docker') {
exportFromEndpoint('/api/admin/export');
exportFromEndpoint(withBaseUrl('/api/admin/export'));
} else if (choice === 'local') {
exportFromEndpoint('/api/admin/exportlocal');
exportFromEndpoint(withBaseUrl('/api/admin/exportlocal'));
}
};
@@ -693,7 +694,7 @@ export default function AdminPage() {
// Save to JSON file in background
try {
console.log('Fetching current pinned data...');
const pinnedRes = await fetch('/api/admin/posts', { method: 'GET' });
const pinnedRes = await fetch(withBaseUrl('/api/admin/posts'), { method: 'GET' });
if (!pinnedRes.ok) {
throw new Error(`Failed to fetch pinned data: ${pinnedRes.status}`);
}
@@ -706,7 +707,7 @@ export default function AdminPage() {
console.log('Updated folderEmojis:', folderEmojis);
console.log('Saving to pinned.json...');
const saveRes = await fetch('/api/admin/posts', {
const saveRes = await fetch(withBaseUrl('/api/admin/posts'), {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ folderEmojis, pinned: pinnedData.pinned || [] }),
@@ -886,7 +887,7 @@ export default function AdminPage() {
</span>
</button>
<a
href="/admin/manage/rust-status"
href={withBaseUrl('/admin/manage/rust-status')}
className="w-full sm:w-auto px-4 py-3 sm:py-2 bg-gradient-to-r from-teal-500 to-blue-500 text-white rounded-xl shadow-lg flex items-center justify-center gap-2 text-sm sm:text-base font-semibold hover:from-teal-600 hover:to-blue-600 transition-all focus:outline-none focus:ring-2 focus:ring-teal-400"
title="View Rust Parser Dashboard"
style={{ minWidth: '160px' }}
@@ -902,7 +903,7 @@ export default function AdminPage() {
</a>
{/* VS Code Editor Button */}
<a
href="/admin/editor"
href={withBaseUrl('/admin/editor')}
className="w-full sm:w-auto px-4 py-3 sm:py-2 bg-gradient-to-r from-gray-700 to-blue-700 text-white rounded-xl shadow-lg flex items-center justify-center gap-2 text-sm sm:text-base font-semibold hover:from-gray-800 hover:to-blue-800 transition-all focus:outline-none focus:ring-2 focus:ring-blue-400"
title="Markdown Bearbeiter"
style={{ minWidth: '160px' }}
@@ -1477,7 +1478,7 @@ export default function AdminPage() {
</div>
))}
</div>
<a href="/admin/manage" className="block mt-6 text-blue-600 hover:underline text-sm sm:text-base">Zur Inhaltsverwaltung</a>
<a href={withBaseUrl('/admin/manage')} className="block mt-6 text-blue-600 hover:underline text-sm sm:text-base">Zur Inhaltsverwaltung</a>
</div>
)}
</div>