<%%= product.name %>
Category: <%%= category %>
Product ID: <%%= id %>
Price: $<%%= product.price %>
Description: <%%= product.description %>
### Install Datastar Starter Kit Source: https://github.com/benallfree/pocketpages/blob/main/packages/starters/datastar/README.md Installs the Datastar starter kit using npx, navigates into the directory, installs dependencies, and starts the PocketBase server. ```bash npx tiged benallfree/pocketpages/packages/starters/datastar . cd datastar npm i pocketbase serve --dir=pb_data --dev ``` -------------------------------- ### Install and Run DaisyUI Docs Starter Source: https://github.com/benallfree/pocketpages/blob/main/packages/starters/daisyui-docs/README.md Installs the starter kit, navigates into the directory, installs dependencies, starts the development server, and runs the PocketBase server. ```bash npx tiged benallfree/pocketpages/starters/daisyui-docs . cd daisyui-docs npm i npm run dev pocketbase serve --dir=pb_data --dev ``` -------------------------------- ### Install MPA Auth Demo Starter Source: https://github.com/benallfree/pocketpages/blob/main/packages/starters/auth/README.md Installs the starter kit, navigates into the directory, installs dependencies, and starts the PocketBase development server and Maildev. ```bash npx tiged benallfree/pocketpages/packages/starters/auth . cd auth npm i pocketbase --dir=pb_data --dev serve bunx maildev ``` -------------------------------- ### Install and Run MVP Starter Kit Source: https://github.com/benallfree/pocketpages/blob/main/packages/starters/mvp/README.md Installs the MVP starter kit using npx and starts a local PocketBase development server. ```bash npx tiged benallfree/pocketpages/starters/mvp . cd mvp pocketbase --dir=pb_data --dev serve ``` -------------------------------- ### Install HTMX Starter Kit Source: https://github.com/benallfree/pocketpages/blob/main/packages/starters/htmx/README.md Installs the HTMX starter kit using npx, navigates into the directory, installs npm dependencies, and starts the PocketBase development server. ```bash npx tiged benallfree/pocketpages/packages/starters/htmx . cd htmx npm i pocketbase serve --dir=pb_data --dev ``` -------------------------------- ### Install and Run Minimal PocketPages Starter Source: https://github.com/benallfree/pocketpages/blob/main/packages/starters/minimal/README.md Use these commands to install the starter kit, navigate to its directory, and start the PocketBase development server. ```bash npx tiged benallfree/pocketpages/starters/minimal . cd minimal pocketbase --dir=pb_data --dev serve ``` -------------------------------- ### Install PocketPages Auth Starter Kit Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/authentication/oauth2.md Use npx to install the authentication starter kit for PocketPages. Navigate into the created directory and install dependencies. ```bash npx tiged benallfree/pocketpages/starters/auth my-auth-app cd my-auth-app npm i ``` -------------------------------- ### Example File Resolution with include() and resolve() Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/private-files.md Shows how `include()` and `resolve()` functions search for files within `_private` directories, starting from the current directory and moving up the tree. ```ejs <%% // In /products/categories/index.ejs: // Looks for category-nav first in local _private, then up the tree include('category-nav.ejs') // Uses /products/categories/_private/category-nav.ejs // Product card isn't in local _private, so checks parent directories include('product-card.ejs') // Uses /products/_private/product-card.ejs // Global layout is found in the root _private include('layout.ejs') // Uses /_private/layout.ejs // Same pattern works for resolve const helpers = resolve('helpers') // Uses local /categories/_private/helpers.js const queries = resolve('queries') // Uses parent /products/_private/queries.js const config = resolve('config') // Uses root /_private/config.js %> ``` -------------------------------- ### Install and Run DaisyUI PocketPages Starter Source: https://github.com/benallfree/pocketpages/blob/main/packages/starters/daisyui/README.md Use these commands to clone the starter kit, install dependencies, and run the development server for both the PocketPages app and PocketBase. ```bash npx tiged benallfree/pocketpages/packages/starters/daisyui . cd daisyui npm i npm run dev pocketbase serve --dir=pb_data --dev ``` -------------------------------- ### Start Development Server Source: https://github.com/benallfree/pocketpages/blob/main/README.md Command to start the PocketPages development server in the root folder. ```bash bun dev ``` -------------------------------- ### Install PocketPages Realtime Plugin Source: https://github.com/benallfree/pocketpages/blob/main/packages/plugins/realtime/README.md Install the plugin using npm. ```bash npm install pocketpages-plugin-realtime ``` -------------------------------- ### Install Auth Starter Kit Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/authentication/overview.md Use this command to download and install the complete authentication starter kit for PocketPages. This kit includes UI, all authentication methods, email verification, account management, password reset, middleware protection, and auth status layout. ```bash npx tiged benallfree/pocketpages/starters/auth . ``` -------------------------------- ### Install PHIO CLI Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/deploying.md Install the PocketHost.IO CLI utility globally to manage deployments to pockethost.io. ```bash npm i -g phio ``` -------------------------------- ### Example Usage with Frontmatter and Dynamic Content Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/plugins/marked.md Demonstrates a complete example combining frontmatter, dynamic content retrieval, and EJS loops within a Markdown file. ```markdown --- title: Getting Started layout: docs --- # <%%%= meta('title') %> <<%%=`script server`%>> const features = pb.collection('features').getFullList() ## Key Features <%%% features.forEach(feature => { %> ### <%%%= feature.name %> <%%%= feature.description %>  <%%% } %> ``` -------------------------------- ### Install Markdown Plugin Source: https://github.com/benallfree/pocketpages/blob/main/packages/plugins/marked/README.md Install the pocketpages-plugin-marked using npm. ```bash npm install pocketpages-plugin-marked ``` -------------------------------- ### Install Bun Source: https://github.com/benallfree/pocketpages/blob/main/README.md Command to install the Bun JavaScript runtime using the official installation script. ```bash curl -fsSL https://bun.sh/install | bash ``` -------------------------------- ### Complete Login Form Example Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/context-api/sign-in-with-password.md Provides a full HTML form example for user login using `signInWithPassword`. It includes input fields for email and password, form submission handling, and error display. ```ejs <%%= if (request.method === 'POST') { try { const { email, password } = formData // Validate required fields if (!email || !password) { throw new Error('Email and password are required') } // Attempt login const authData = signInWithPassword(email, password) // Successful login - redirect to dashboard redirect('/dashboard') } catch (error) { // Login failed %>
Category: <%%= category %>
Product ID: <%%= id %>
Price: $<%%= product.price %>
Description: <%%= product.description %>
<%%= stringify(params) %>
Please check your email for the OTP code and enter it below.
``` -------------------------------- ### Complete Response with Headers and JSON Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/context-api/response.md Example demonstrating setting multiple headers, a secure cookie, and sending a JSON response. ```ejs <%%= // Set headers response.header('Cache-Control', 'no-cache') response.header('X-Custom-Header', 'custom-value') // Set a cookie response.cookie('session', 'xyz789', { httpOnly: true, secure: true }) // Send JSON response response.json(200, { success: true, data: { message: 'Operation completed' } }) %> ``` -------------------------------- ### Example Usage: Basic Request Information Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/context-api/request.md Demonstrates how to retrieve the HTTP method, URL, and specific headers from the request object. ```APIDOC ## Example Usage: Basic Request Information ### Get Method and URL ```ejs <%% // Get method and URL const { method, url } = request // Access query parameters const page = url.query.page const sort = url.query.sort // Get headers const userAgent = request.header('User-Agent') %> ``` ``` -------------------------------- ### Product List Data Loader Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/context-api/data.md Example of a `+load.js` file for a product list route, fetching and returning active categories. ```javascript /** @type {import('pocketpages').PageDataLoaderFunc} */ module.exports = function (api) { const categories = $app.findRecordsByFilter('categories', { filter: 'active = true', sort: 'name', }) return { categories } ``` -------------------------------- ### Documenting Required Environment Variables Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/secrets.md Shows an example of documenting required environment variables using JSDoc comments for clarity. ```javascript /** * Required environment variables: * - API_KEY: External service API key * - DB_PASSWORD: Database password * - SMTP_PASSWORD: Email service password */ ``` -------------------------------- ### Example PocketPages Directory Structure Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/directory-structure.md Illustrates the mandatory `pb_hooks/pages/` root directory and how to organize flat and nested page files using EJS templates. ```plaintext pb_hooks/ pages/ index.ejs about.ejs contact.ejs products/ index.ejs details.ejs ``` -------------------------------- ### Counter with Realtime Updates Source: https://github.com/benallfree/pocketpages/blob/main/packages/plugins/datastar/README.md This example shows how to increment a counter stored in the application and then return the updated counter, presumably for a realtime update. ```javascript // Increment counter $app.runInTransaction(() => { store('count', (store('count') || 1) + 1) }) // Return updated counter <%- include('count.ejs') %> ``` -------------------------------- ### Include Partial using Absolute Path Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/partials.md Demonstrates how to use an absolute path starting from the root to explicitly include a specific partial file. ```ejs <%%- include('/blog/_private/blog-sidebar.ejs', { api }) %> // Explicitly uses /blog/_private/blog-sidebar.ejs ``` -------------------------------- ### onRequest Hook Example Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/plugins/authoring.md The onRequest hook is called at the start of each request to modify request or response objects. ```javascript onRequest({ request, response }) { // Modify request/response // Add headers, check auth, etc. } ``` -------------------------------- ### Micro Dash Collection Operations Example Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/plugins/micro-dash.md Demonstrates using forEach, keys, and values for iterating and accessing data within collections. ```ejs <%%% // Iterate over arrays or objects forEach([1, 2, 3], (value) => { echo(value) }) // Get object keys const obj = { a: 1, b: 2 } const objKeys = keys(obj) // ['a', 'b'] // Get object values const objValues = values(obj) // [1, 2] %> ``` -------------------------------- ### Get Page Title in EJS Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/context-api/meta.md Example of retrieving the 'title' metadata value within an EJS template. This is useful for dynamically setting the page's title. ```ejs <%% const pageTitle = meta('title'); %> ``` -------------------------------- ### Copy GitHub Actions Starter for pockethost.io Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/deploying.md Copy the starter files for setting up automated deployments to pockethost.io using Github Actions. ```bash cp -r node_modules/pocketpages/starters/deploy-pockethost-ga . ``` -------------------------------- ### Client-Side Button Click Binding Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/plugins/datastar.md Example of using a data-on-click attribute to trigger a GET request to an API endpoint and update a span with data-bind-count. Assumes Datastar loader script is included. ```html ``` -------------------------------- ### Copy Starter Files for Fly.io Deployment Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/deploying.md Copy the starter files for setting up deployment to Fly.io. This includes a Dockerfile and fly.toml. ```bash cp -r node_modules/pocketpages/starters/deploy-fly-ga . ``` -------------------------------- ### Basic EJS Template Example Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/loading-data.md A simple EJS template demonstrating how to display site name and iterate through navigation items using loaded data. ```ejs
```
--------------------------------
### SPA Example with Content Updates
Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/plugins/datastar.md
Demonstrates a full HTML structure with SPA mode enabled, where navigation links update content within a specified div.
```html
<%%- datastar.scripts({ spa: { scope: 'nav', selector: 'content' } }) %>
This is the main content of the product page.
``` -------------------------------- ### Simple Layout Using Slot Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/layouts.md A minimal EJS layout example that uses the 'slot' variable to render its content. ```ejs <%%- slot %> ``` -------------------------------- ### Using Global API in Libraries (Example) Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/global-api/index.md Demonstrates how to use Global API functions like dbg and stringify within a custom library function when imported via require('pocketpages').globalApi. ```javascript // myLibrary.js const { globalApi } = require('pocketpages') const { dbg, stringify } = globalApi function processUserData(user) { dbg('Processing user:', stringify(user)) // ... processing logic } module.exports = { processUserData } ``` -------------------------------- ### Section-Specific Utilities Module Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/context-api/resolve.md Example of a section-specific utility module for product queries, exporting functions using `module.exports`. ```javascript // products/_private/queries.js module.exports = { getActiveProducts: () => { return $app.findRecordsByExpr('products', 'status = ?', ['active']) }, getCategoryProducts: (categoryId) => { return $app.findRecordsByExpr('products', 'category = ?', [categoryId]) }, } ``` -------------------------------- ### Configuring with Global API Access Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/config.md Example of exporting a function from `+config.js` that receives the global API, allowing access to environment variables and other global settings. ```javascript module.exports = function (api) { return { plugins: [ { name: 'pocketpages-plugin-js-sdk', host: api.env('POCKETPAGES_HOST'), }, 'pocketpages-plugin-ejs', ], debug: true, } } ``` -------------------------------- ### Basic Hello World Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/_private/overview.md A simple EJS template to display 'Hello, world!'. This is the most basic example of a PocketPages template. ```ejs // index.ejs <%%= `Hello, world!` %> ``` -------------------------------- ### Serve a File Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/context-api/response.md Use the `file()` method to serve a file from the filesystem. Specify the file path as an argument. ```ejs <%%= // Serve a PDF file response.file('/path/to/document.pdf') %> ``` -------------------------------- ### Get Object Values with values Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/global-api/micro-dash.md Retrieve an array of an object's own enumerable property values using the values function. ```javascript const { values } = require('pocketpages') const obj = { a: 1, b: 2, c: 3 } const propertyValues = values(obj) // => [1, 2, 3] ``` -------------------------------- ### Sign In and Register with Password Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/authentication/password.md Use `signInWithPassword` to authenticate existing users or `registerWithPassword` to create new users. Both return an AuthData object. ```javascript const authData = api.signInWithPassword(email, password) const authData = api.registerWithPassword(email, password) ``` -------------------------------- ### HTTP Method-Specific Loaders (POST Example) Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/loading-data.md Illustrates the use of method-specific loaders, showing a +post.js file that would run only for POST requests after the general +load.js. ```javascript // Example for pb_hooks/pages/contact/+post.js // This code would execute only for POST requests to the /contact route. ``` -------------------------------- ### Get Object Keys with keys Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/global-api/micro-dash.md Retrieve an array of an object's own enumerable property names using the keys function. ```javascript const { keys } = require('pocketpages') const obj = { a: 1, b: 2, c: 3 } const propertyNames = keys(obj) // => ['a', 'b', 'c'] ``` -------------------------------- ### Get Unauthenticated Client in EJS Source: https://github.com/benallfree/pocketpages/blob/main/packages/plugins/js-sdk/README.md Obtain an anonymous PocketBase client in an EJS template by calling `pb()` without arguments. ```ejs <%% // Get an anonymous client const client = pb() %> ``` -------------------------------- ### Establish SSE Connection and Handle Events Source: https://github.com/benallfree/pocketpages/blob/main/packages/plugins/datastar/src/realtime.html Connects to the SSE endpoint, listens for 'PB_CONNECT' and 'datastar' events, and dispatches custom events. Requires a fetch call to subscribe to specific data streams after initial connection. ```javascript const source = new EventSource('/api/realtime') // URL to your SSE endpoint source.addEventListener('PB_CONNECT', function (event) { const e = JSON.parse(event.data) // console.log('PB_CONNECT event:', e) const { clientId } = e fetch(`/api/realtime`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ clientId, subscriptions: ['datastar'], }), }).catch(console.error) patchSignals({ clientId }) }) source.addEventListener('datastar', function (event) { const e = JSON.parse(event.data) // console.log('datastar event:', e) document.dispatchEvent( new CustomEvent('datastar-fetch', { detail: e, }) ) }) ``` -------------------------------- ### Get Authenticated Client in EJS Source: https://github.com/benallfree/pocketpages/blob/main/packages/plugins/js-sdk/README.md Retrieve an authenticated PocketBase client within an EJS template using the request context. ```ejs <%% // Get an authenticated client for the current request const client = pb({ request }) // Use any PocketBase SDK method with the authenticated context const records = client.collection('posts').getFullList({ sort: '-created', expand: 'author', }) %> ``` -------------------------------- ### EJS Smart Partial Resolution Example Source: https://github.com/benallfree/pocketpages/blob/main/packages/plugins/ejs/README.md Illustrates how the `include` function resolves partials by searching up the directory tree in `_private` folders, trying configured extensions. ```ejs <%%- include('header', { title: 'My Page' }) %> ``` -------------------------------- ### Initialize PocketBase Client Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/global-api/pb.md Instantiate the PocketBase client for use in JSVM. This client is automatically configured based on your `+config.js` settings. ```javascript const pb = require('pocketpages').pb() // Use any PocketBase SDK method const users = pb.collection('users').getFullList() const posts = pb.collection('posts').getList(1, 20) ``` -------------------------------- ### Create New PocketPages Project with npm Source: https://github.com/benallfree/pocketpages/blob/main/packages/create-pocketpages/README.md Use this command to scaffold a new PocketPages project using npm. ```bash npm create pocketpages ``` -------------------------------- ### Example Plugin: API Extension Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/plugins/authoring.md An API extension plugin that adds a formatDate method to the context API for formatting dates. ```javascript module.exports = (config, options) => { return { onExtendContextApi: ({ api }) => { api.formatDate = (date) => { return new Date(date).toLocaleDateString() } }, } } ``` -------------------------------- ### Running PocketBase with Data Directory Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/installation.md This command starts PocketBase, ensuring it uses the current directory for data storage. This is a crucial step for PocketPages to function correctly. ```bash cd your_project_directory pocketbase serve --dir=pb_data ``` -------------------------------- ### onResponse Hook Example Source: https://github.com/benallfree/pocketpages/blob/main/packages/site/pb_hooks/pages/(main)/docs/plugins/authoring.md The onResponse hook performs final processing before sending the response, such as modifying output or handling caching. ```javascript onResponse({ api, content }) { // Modify final output // Add headers // Handle caching return false; // Continue processing } ```