-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.html
More file actions
142 lines (135 loc) · 5.83 KB
/
editor.html
File metadata and controls
142 lines (135 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Editor — Namma Kudla</title>
<link rel="stylesheet" href="style.css" />
<style>
.editor-grid{display:grid;grid-template-columns:1fr 320px;gap:1rem}
.list-item{border:1px solid #eee;padding:.5rem;border-radius:8px;margin-bottom:.5rem}
label{display:block;margin-top:.5rem}
</style>
</head>
<body>
<header class="site-header">
<div class="container header-inner">
<a class="brand" href="index.html">Namma Kudla - Editor</a>
<nav class="nav">
<a href="index.html" class="active">Home</a>
<a href="post.html">Blog</a>
<a href="destinations.html">Destinations</a>
<div class="dropdown">
<button class="dropbtn">Dashboard</button>
<div class="dropdown-content">
<a href="about.html">About</a>
<a href="stories.html">Stories</a>
<a href="maps.html">Maps</a>
<a href="community.html">Community</a>
<a href="guide.html">Guides</a>
<a href="editor.html" class="active">Editor</a>
</div>
</div>
<a href="contact.html">Contact</a>
</nav>
</nav>
</div>
</header>
<main class="container">
<h1>Blog Editor (Local only)</h1>
<div class="editor-grid">
<section>
<form id="post-form">
<input type="hidden" id="post-id" />
<label>Title<input id="title" required /></label>
<label>Slug<input id="slug" required /></label>
<label>Author<input id="author" required /></label>
<label>Date<input id="date" type="date" /></label>
<label>Image URL<input id="image" placeholder="assets/images/..." /></label>
<label>Excerpt<textarea id="excerpt" rows="2"></textarea></label>
<label>Content (HTML)<textarea id="content" rows="8"></textarea></label>
<label>Category<input id="category" /></label>
<label>Tags (comma separated)<input id="tags" /></label>
<div style="margin-top:.5rem">
<button type="submit">Save Post</button>
<button id="clear-btn" type="button">Clear</button>
</div>
</form>
</section>
<aside>
<h3>Existing Posts</h3>
<div id="posts-admin"></div>
<button id="seed-btn" style="margin-top:.5rem">Reset to Seed Data</button>
</aside>
</div>
</main>
<script src="app.js"></script>
<script>
// Editor logic using functions in app.js
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('post-form');
const clearBtn = document.getElementById('clear-btn');
const postsAdmin = document.getElementById('posts-admin');
const seedBtn = document.getElementById('seed-btn');
function populateList(){
const all = getPosts();
postsAdmin.innerHTML = all.map(p => `
<div class="list-item">
<strong>${p.title}</strong><br/>
<small>${p.author} • ${p.date}</small>
<div style="margin-top:.5rem">
<button data-id="${p.id}" class="edit-btn">Edit</button>
<button data-id="${p.id}" class="del-btn">Delete</button>
<a href="../post.html?slug=${p.slug}" target="_blank">View</a>
</div>
</div>
`).join('');
// attach handlers
document.querySelectorAll('.edit-btn').forEach(b => b.addEventListener('click', e=>{
const id = e.target.dataset.id;
const post = getPosts().find(p => p.id === id);
if(!post) return alert('Post not found');
document.getElementById('post-id').value = post.id;
document.getElementById('title').value = post.title;
document.getElementById('slug').value = post.slug;
document.getElementById('author').value = post.author;
document.getElementById('date').value = post.date;
document.getElementById('image').value = post.image;
document.getElementById('excerpt').value = post.excerpt;
document.getElementById('content').value = post.content;
document.getElementById('category').value = post.category || '';
document.getElementById('tags').value = (post.tags || []).join(',');
}));
document.querySelectorAll('.del-btn').forEach(b => b.addEventListener('click', e=>{
const id = e.target.dataset.id;
if(!confirm('Delete this post?')) return;
deletePost(id);
populateList();
}));
}
form.addEventListener('submit', e=>{
e.preventDefault();
const post = {
id: document.getElementById('post-id').value || ('p'+Date.now()),
title: document.getElementById('title').value.trim(),
slug: document.getElementById('slug').value.trim().replace(/\s+/g,'-').toLowerCase(),
author: document.getElementById('author').value.trim(),
date: document.getElementById('date').value || new Date().toISOString().split('T')[0],
image: document.getElementById('image').value.trim() || 'assets/images/placeholder.jpg',
excerpt: document.getElementById('excerpt').value,
content: document.getElementById('content').value,
category: document.getElementById('category').value.trim(),
tags: document.getElementById('tags').value.split(',').map(t=>t.trim()).filter(Boolean)
};
saveOrUpdatePost(post);
form.reset();
populateList();
alert('Post saved locally.');
});
clearBtn.addEventListener('click', ()=>document.getElementById('post-form').reset());
seedBtn.addEventListener('click', ()=>{ resetSeedPosts(); populateList(); alert('Seed data restored'); });
populateList();
});
</script>
</body>
</html>