site-builder: lock landing page to index.html regardless of name

The first page is now treated as the landing page: it always publishes to
index.html no matter what the user names it, and its slug is forced to
'index' in state so .htaccess clean-URL rewrites stay consistent.

- useWhpApi.ts: force pages[0].filename='index.html' at save time
- PageContext.tsx: heal pages[0].slug to 'index' on load and on rename
- PagesPanel.tsx: "LANDING" badge on first page, slug shown as '/',
  rename hides slug input (locked), delete button hidden

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-25 12:14:26 -07:00
parent 330032eea3
commit 7b747f775f
3 changed files with 76 additions and 24 deletions

View File

@@ -51,8 +51,11 @@ export function useWhpApi() {
// Build the pages array with HTML for each page // Build the pages array with HTML for each page
// For the active page, use the freshly exported HTML from the canvas; // For the active page, use the freshly exported HTML from the canvas;
// for others, export from their stored craft state // for others, export from their stored craft state
const pagesPayload = pages.map((page) => { const pagesPayload = pages.map((page, i) => {
const filename = (page.slug === 'index' ? 'index' : page.slug) + '.html'; // The first page is ALWAYS the landing page → publishes to index.html
// regardless of the page name/slug. Apache serves '/' from index.html,
// and renaming the first page should not break the root URL.
const filename = i === 0 ? 'index.html' : page.slug + '.html';
let pageHtml = ''; let pageHtml = '';
if (page.id === activePageId) { if (page.id === activePageId) {
@@ -77,10 +80,13 @@ export function useWhpApi() {
// Build pages_craft_state array: for each page, store its craft state // Build pages_craft_state array: for each page, store its craft state
// For the currently active page, always use the fresh canvas state (currentCraftState) // For the currently active page, always use the fresh canvas state (currentCraftState)
// since page.craftState may be stale (not updated until page switch) // since page.craftState may be stale (not updated until page switch)
const pagesGrapesjs = pages.map((page) => ({ const pagesGrapesjs = pages.map((page, i) => ({
id: page.id, id: page.id,
name: page.name, name: page.name,
slug: page.slug, // Pin the landing page's slug to 'index' on the wire too, so that on
// reload the editor's clean-URL routing (.htaccess rewrite of /name →
// name.html) lines up with the file we just wrote (index.html).
slug: i === 0 ? 'index' : page.slug,
craftState: page.id === activePageId ? currentCraftState : (page.craftState || null), craftState: page.id === activePageId ? currentCraftState : (page.craftState || null),
})); }));

View File

@@ -145,7 +145,9 @@ export const PagesPanel: React.FC = () => {
</div> </div>
{/* Page list */} {/* Page list */}
{pages.map((page) => ( {pages.map((page, pageIndex) => {
const isLanding = pageIndex === 0;
return (
<div key={page.id}> <div key={page.id}>
{editingId === page.id ? ( {editingId === page.id ? (
/* Editing mode */ /* Editing mode */
@@ -176,14 +178,25 @@ export const PagesPanel: React.FC = () => {
if (e.key === 'Escape') setEditingId(null); if (e.key === 'Escape') setEditingId(null);
}} }}
/> />
<input {isLanding ? (
type="text" <div style={{
value={editSlug} fontSize: 10,
onChange={(e) => setEditSlug(e.target.value)} color: 'var(--color-text-dim)',
placeholder="page-slug" padding: '4px 2px',
className="control-input" fontStyle: 'italic',
style={{ fontSize: 11 }} }}>
/> Landing page URL locked to <code>/</code>
</div>
) : (
<input
type="text"
value={editSlug}
onChange={(e) => setEditSlug(e.target.value)}
placeholder="page-slug"
className="control-input"
style={{ fontSize: 11 }}
/>
)}
<div style={{ display: 'flex', gap: 6 }}> <div style={{ display: 'flex', gap: 6 }}>
<button <button
onClick={() => handleRename(page.id)} onClick={() => handleRename(page.id)}
@@ -298,12 +311,36 @@ export const PagesPanel: React.FC = () => {
page.id === activePageId page.id === activePageId
? 'var(--color-accent)' ? 'var(--color-accent)'
: 'var(--color-text)', : 'var(--color-text)',
display: 'flex',
alignItems: 'center',
gap: 6,
overflow: 'hidden',
}}
>
<span style={{
overflow: 'hidden', overflow: 'hidden',
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
}} }}>{page.name}</span>
> {isLanding && (
{page.name} <span
title="This is the landing page — published as the root URL (index.html)"
style={{
fontSize: 9,
fontWeight: 700,
textTransform: 'uppercase',
letterSpacing: '0.5px',
color: '#fbbf24',
background: 'rgba(245, 158, 11, 0.15)',
border: '1px solid rgba(245, 158, 11, 0.35)',
padding: '1px 5px',
borderRadius: 'var(--radius-sm)',
flexShrink: 0,
}}
>
<i className="fa fa-home" style={{ marginRight: 3 }} />Landing
</span>
)}
</div> </div>
<div <div
style={{ style={{
@@ -312,7 +349,7 @@ export const PagesPanel: React.FC = () => {
marginTop: 2, marginTop: 2,
}} }}
> >
/{page.slug} {isLanding ? '/' : '/' + page.slug}
</div> </div>
</div> </div>
<div <div
@@ -338,7 +375,7 @@ export const PagesPanel: React.FC = () => {
> >
&#9998; &#9998;
</button> </button>
{pages.length > 1 && ( {pages.length > 1 && !isLanding && (
<button <button
onClick={() => setDeleteConfirmId(page.id)} onClick={() => setDeleteConfirmId(page.id)}
title="Delete" title="Delete"
@@ -363,7 +400,8 @@ export const PagesPanel: React.FC = () => {
</div> </div>
)} )}
</div> </div>
))} );
})}
{/* Add page section */} {/* Add page section */}
{isAdding ? ( {isAdding ? (

View File

@@ -276,9 +276,14 @@ export const PageProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
const renamePage = useCallback((pageId: string, name: string, slug: string) => { const renamePage = useCallback((pageId: string, name: string, slug: string) => {
setPages((prev) => setPages((prev) =>
prev.map((p) => prev.map((p, i) => {
p.id === pageId ? { ...p, name, slug: slug || slugify(name) } : p, if (p.id !== pageId) return p;
), // First page is the landing page — its slug is locked to 'index' so
// the file always publishes to index.html regardless of the user-set
// name. The display name can change freely.
const nextSlug = i === 0 ? 'index' : (slug || slugify(name));
return { ...p, name, slug: nextSlug };
}),
); );
}, []); }, []);
@@ -294,10 +299,13 @@ export const PageProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
/** Allow external code (e.g., load from API) to restore pages with craft states */ /** Allow external code (e.g., load from API) to restore pages with craft states */
const setPagesCraftState = useCallback((pagesData: { id: string; name: string; slug: string; craftState: string | null }[]) => { const setPagesCraftState = useCallback((pagesData: { id: string; name: string; slug: string; craftState: string | null }[]) => {
setPages(pagesData.map((p) => ({ setPages(pagesData.map((p, i) => ({
id: p.id, id: p.id,
name: p.name, name: p.name,
slug: p.slug, // Heal legacy projects whose first page was saved with slug='home' (or
// any other) before the landing-page rule existed. The first page is
// ALWAYS the landing page → slug 'index' → file index.html.
slug: i === 0 ? 'index' : p.slug,
craftState: p.craftState, craftState: p.craftState,
headCode: '', headCode: '',
}))); })));