diff --git a/app/default/templates/base.php b/app/default/templates/base.php index d739dbe..ce25bfd 100644 --- a/app/default/templates/base.php +++ b/app/default/templates/base.php @@ -54,8 +54,5 @@

- - - diff --git a/app/helpers.php b/app/helpers.php index c9c722c..489202e 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -132,22 +132,6 @@ function findPageCss(string $dirPath, string $contentDir): ?array { ]; } -function findPageJs(string $dirPath, string $contentDir): ?array { - $jsFile = "$dirPath/script.js"; - if (!file_exists($jsFile) || !is_file($jsFile)) { - return null; - } - - $relativePath = str_replace($contentDir, '', $dirPath); - $relativePath = trim($relativePath, '/'); - $jsUrl = '/' . ($relativePath ? $relativePath . '/' : '') . 'script.js'; - - return [ - 'url' => $jsUrl, - 'hash' => hash_file('md5', $jsFile) - ]; -} - function extractMetaDescription(string $dirPath, ?array $metadata): ?string { // 1. Check for search_description in metadata if ($metadata && isset($metadata['search_description'])) { diff --git a/app/rendering.php b/app/rendering.php index c4a099a..ef4e57a 100644 --- a/app/rendering.php +++ b/app/rendering.php @@ -57,8 +57,6 @@ function renderTemplate(Context $ctx, string $content, int $statusCode = 200): v 'metaDescription' => $ctx->get('metaDescription'), 'pageCssUrl' => $ctx->get('pageCssUrl'), 'pageCssHash' => $ctx->get('pageCssHash'), - 'pageJsUrl' => $ctx->get('pageJsUrl'), - 'pageJsHash' => $ctx->get('pageJsHash'), 'feedUrl' => $ctx->get('feedUrl') ], $ctx); @@ -90,10 +88,6 @@ function renderMultipleFiles(Context $ctx, array $files, string $pageDir): void $pageCssUrl = $pageCss['url'] ?? null; $pageCssHash = $pageCss['hash'] ?? null; - $pageJs = findPageJs($pageDir, $ctx->contentDir); - $pageJsUrl = $pageJs['url'] ?? null; - $pageJsHash = $pageJs['hash'] ?? null; - $coverImage = findCoverImage($pageDir); $socialImageUrl = null; if ($coverImage) { @@ -110,8 +104,6 @@ function renderMultipleFiles(Context $ctx, array $files, string $pageDir): void 'metaDescription' => $metaDescription, 'pageCssUrl' => $pageCssUrl, 'pageCssHash' => $pageCssHash, - 'pageJsUrl' => $pageJsUrl, - 'pageJsHash' => $pageJsHash, 'socialImageUrl' => $socialImageUrl ], $ctx); diff --git a/app/router.php b/app/router.php index 9772872..d9710e0 100644 --- a/app/router.php +++ b/app/router.php @@ -42,7 +42,6 @@ if (file_exists($contentAssetPath) && is_file($contentAssetPath)) { 'woff2' => 'font/woff2', 'ttf' => 'font/ttf', 'otf' => 'font/otf', - 'js' => 'application/javascript', ]; $extLower = strtolower($ext); @@ -206,14 +205,10 @@ switch ($parsedPath['type']) { $pageTitle = $metadata['title'] ?? null; $metaDescription = extractMetaDescription($dir, $metadata); - // Check for page-specific CSS and JS + // Check for page-specific CSS $pageCss = findPageCss($dir, $ctx->contentDir); $pageCssUrl = $pageCss['url'] ?? null; $pageCssHash = $pageCss['hash'] ?? null; - - $pageJs = findPageJs($dir, $ctx->contentDir); - $pageJsUrl = $pageJs['url'] ?? null; - $pageJsHash = $pageJs['hash'] ?? null; // Build feed URL if feed is enabled $langPrefix = $ctx->get('langPrefix', ''); @@ -226,8 +221,6 @@ switch ($parsedPath['type']) { $ctx->set('metaDescription', $metaDescription); $ctx->set('pageCssUrl', $pageCssUrl); $ctx->set('pageCssHash', $pageCssHash); - $ctx->set('pageJsUrl', $pageJsUrl); - $ctx->set('pageJsHash', $pageJsHash); $ctx->set('feedUrl', $feedUrl); // Let plugins add template variables @@ -238,8 +231,6 @@ switch ($parsedPath['type']) { 'metaDescription' => $metaDescription, 'pageCssUrl' => $pageCssUrl, 'pageCssHash' => $pageCssHash, - 'pageJsUrl' => $pageJsUrl, - 'pageJsHash' => $pageJsHash, 'items' => $items, 'pageContent' => $pageContent, 'feedUrl' => $feedUrl diff --git a/docs/02-tutorial/02-styling.md b/docs/02-tutorial/02-styling.md index 1d4b064..0aa78ba 100644 --- a/docs/02-tutorial/02-styling.md +++ b/docs/02-tutorial/02-styling.md @@ -241,33 +241,6 @@ FolderWeb automatically loads and includes page-specific styles with cache-busti ``` -## Page-Specific Scripts - -For small progressive enhancements, you can add a `script.js` file to a content directory: - -``` -content/portfolio/ -├── index.md -├── styles.css -└── script.js -``` - -**script.js:** -```js -// Small enhancement for this page only -document.querySelector('.portfolio-grid')?.addEventListener('click', (e) => { - // ... -}); -``` - -FolderWeb automatically loads the script with `defer` (non-blocking) and cache-busting: - -```html - -``` - -The script tag is placed before ``, so it runs after the page has been parsed. This is ideal for progressive enhancement — the page works without JavaScript, but gets enhanced when it's available. - ## Dark Mode Add dark mode with CSS variables and `prefers-color-scheme`: diff --git a/docs/02-tutorial/03-templates.md b/docs/02-tutorial/03-templates.md index cc7d9eb..5e14654 100644 --- a/docs/02-tutorial/03-templates.md +++ b/docs/02-tutorial/03-templates.md @@ -128,10 +128,6 @@ Let's modify `base.php` to add your site name and custom navigation: Generated in s

- - - - ``` @@ -305,7 +301,6 @@ $languageUrls // Links to other language versions $translations // Translated UI strings $cssHash // Cache-busting hash for CSS $pageCssUrl // Page-specific CSS URL (if exists) -$pageJsUrl // Page-specific JS URL (if exists) $pageLoadTime // Page generation time ``` diff --git a/docs/03-reference/03-template-variables.md b/docs/03-reference/03-template-variables.md index 47ea737..9bef00b 100644 --- a/docs/03-reference/03-template-variables.md +++ b/docs/03-reference/03-template-variables.md @@ -211,27 +211,6 @@ MD5 hash of page-specific CSS for cache busting. **Optional:** Only set if `$pageCssUrl` exists **Example:** See `$pageCssUrl` above -### `$pageJsUrl` - -URL to page-specific JavaScript file. - -**Type:** String (URL) -**Optional:** Only set if `script.js` exists in content directory -**Example:** -```php - - - -``` - -### `$pageJsHash` - -MD5 hash of page-specific JavaScript for cache busting. - -**Type:** String (MD5 hash) -**Optional:** Only set if `$pageJsUrl` exists -**Example:** See `$pageJsUrl` above - ### `$feedUrl` URL to the Atom feed for the current list page. @@ -436,8 +415,6 @@ Then use in templates: | `$translations` | ✓ | — | — | | `$pageCssUrl` | ✓ | — | — | | `$pageCssHash` | ✓ | — | — | -| `$pageJsUrl` | ✓ | — | — | -| `$pageJsHash` | ✓ | — | — | | `$feedUrl` | ✓ | — | — | | `$metadata` | — | ✓ | ✓ | | `$pageContent` | — | — | ✓ | diff --git a/docs/04-development/02-content-system.md b/docs/04-development/02-content-system.md index b821dbb..c0d6970 100644 --- a/docs/04-development/02-content-system.md +++ b/docs/04-development/02-content-system.md @@ -126,12 +126,6 @@ Checks extensions in `COVER_IMAGE_EXTENSIONS` order: `jpg`, `jpeg`, `png`, `webp Returns `['url' => string, 'hash' => string]` or null. Hash is MD5 of file content for cache busting. -## Page-Specific JavaScript - -**`findPageJs(string $dirPath, string $contentDir): ?array`** — Checks for `script.js` in content directory. - -Returns `['url' => string, 'hash' => string]` or null. Hash is MD5 of file content for cache busting. The script is loaded with the `defer` attribute in `base.php`, placed before `` for non-blocking progressive enhancement. - ## Meta Description Extraction **`extractMetaDescription(string $dirPath, ?array $metadata): ?string`** diff --git a/docs/04-development/06-templates.md b/docs/04-development/06-templates.md index e6af526..5c2a512 100644 --- a/docs/04-development/06-templates.md +++ b/docs/04-development/06-templates.md @@ -59,8 +59,6 @@ Variables are injected via `extract()` — each array key becomes a local variab | `$homeLabel` | string | yes | Home link text | | `$pageCssUrl` | ?string | no | Page-specific CSS URL | | `$pageCssHash` | ?string | no | CSS cache-bust hash | -| `$pageJsUrl` | ?string | no | Page-specific JS URL | -| `$pageJsHash` | ?string | no | JS cache-bust hash | | `$feedUrl` | ?string | no | Atom feed URL (only on lists with `feed = true`) | | `$currentLang` | string | plugin | Language code (from languages plugin) | | `$langPrefix` | string | plugin | URL language prefix | diff --git a/docs/04-development/07-rendering.md b/docs/04-development/07-rendering.md index b2b49d8..721f676 100644 --- a/docs/04-development/07-rendering.md +++ b/docs/04-development/07-rendering.md @@ -23,7 +23,7 @@ Used for both frontpage and page views: 1. Load metadata for `$pageDir` 2. Load page plugins (from metadata `plugins` field) 3. Render all content files, concatenate HTML -4. Compute: `$pageTitle`, `$metaDescription`, `$pageCssUrl`/`$pageCssHash`, `$pageJsUrl`/`$pageJsHash`, `$socialImageUrl` +4. Compute: `$pageTitle`, `$metaDescription`, `$pageCssUrl`/`$pageCssHash`, `$socialImageUrl` 5. Fire `Hook::TEMPLATE_VARS` with all variables 6. `extract()` variables → render `page.php` → capture output as `$content` 7. Render `base.php` with `$content` + base variables @@ -37,12 +37,12 @@ Handled directly in `router.php` (not a separate function): 2. Load metadata, check `hide_list` 3. Select list template from `page_template` metadata 4. Call `buildListItems()` from `helpers.php` (builds + sorts items) -5. Store `pageTitle`, `metaDescription`, `pageCssUrl`, `pageCssHash`, `pageJsUrl`, `pageJsHash`, `feedUrl` on context +5. Store `pageTitle`, `metaDescription`, `pageCssUrl`, `pageCssHash`, `feedUrl` on context 6. Fire `Hook::TEMPLATE_VARS` 7. Render list template → capture as `$content` 8. Pass to `renderTemplate()` which renders `base.php` -**`renderTemplate(Context $ctx, string $content, int $statusCode = 200): void`** — Wraps content in base template. Used for list views and error pages. Reads `pageTitle`, `metaDescription`, `pageCssUrl`, `pageCssHash`, `pageJsUrl`, `pageJsHash`, and `feedUrl` from the context object (set by the list case in `router.php`). For error pages, these context keys are unset, so base.php receives nulls. +**`renderTemplate(Context $ctx, string $content, int $statusCode = 200): void`** — Wraps content in base template. Used for list views and error pages. Reads `pageTitle`, `metaDescription`, `pageCssUrl`, `pageCssHash`, and `feedUrl` from the context object (set by the list case in `router.php`). For error pages, these context keys are unset, so base.php receives nulls. ## Atom Feed Rendering @@ -79,9 +79,9 @@ setCachedMarkdown(string $filePath, string $html, string $langPrefix = ''): void Before content routing, the router serves static files from content directory with an explicit MIME type allowlist: -`css`, `jpg`, `jpeg`, `png`, `gif`, `webp`, `svg`, `pdf`, `woff`, `woff2`, `ttf`, `otf`, `js` +`css`, `jpg`, `jpeg`, `png`, `gif`, `webp`, `svg`, `pdf`, `woff`, `woff2`, `ttf`, `otf` -Files not in this list are not served as static assets. +Files not in this list are not served as static assets. Notably, `.js` files are excluded — JavaScript must be placed in `custom/assets/` to be served (at the document root URL), or linked from an external source. ### Custom Assets (router.php) @@ -100,9 +100,9 @@ Files in `custom/assets/` are served at the document root URL. Example: `custom/ MIME types resolved from extension map, falling back to `mime_content_type()`. -## CSS and JS Cache Busting +## CSS Cache Busting -Page-specific CSS and JS get an MD5 hash appended: `?v={hash}`. Computed by `findPageCss()` and `findPageJs()` respectively. The default theme's CSS is linked directly without hash (uses browser caching). +Page-specific CSS gets an MD5 hash appended: `?v={hash}`. Computed by `findPageCss()`. The default theme's CSS is linked directly without hash (uses browser caching). ## Parsedown