}
```
--------------------------------
### Upgrade Lume Command
Source: https://lume.land/docs/overview/installation
Command to upgrade the Lume version in a project to the latest stable or development version. Useful for staying updated with new features and bug fixes.
```shell
deno task lume upgrade
```
```shell
deno task lume upgrade --dev
```
--------------------------------
### Install Lume CLI
Source: https://lume.land/docs/overview/command-line
Installs the Lume CLI script globally, allowing you to use the 'lume' command directly instead of 'deno task lume'. This command requires permissions to run, access environment variables, and read files. It ensures the latest version is installed and reloads any existing installation.
```bash
deno install --allow-run --allow-env --allow-read --name lume --force --reload --global https://deno.land/x/lume_cli/mod.ts
```
--------------------------------
### Basic Lume Layout Template (Vento)
Source: https://lume.land/docs/creating-pages/layouts
An example of a basic HTML layout template using the Vento template engine. It demonstrates how to insert dynamic content like the page's `title` and rendered `content`.
```html
{{ title }}
{{ content }}
```
--------------------------------
### Lume Server Custom Middleware Implementation
Source: https://lume.land/docs/core/server
This example illustrates how to implement custom middleware for the Lume server. The middleware function receives a request, passes it to the next middleware in the chain, and can then modify the response before returning it. This allows for advanced request and response handling.
```typescript
server.use(async (request, next) => {
// Here you can modify the request before being passed to next middlewares
const response = await next(request);
// Here you can modify the response before being returned to the previous middleware
return response;
});
```
--------------------------------
### Create Dynamic Pages with Lume Processors
Source: https://context7.com/context7/lume_land/llms.txt
Processors can dynamically create new pages. This example shows how to minify CSS and then create a corresponding source map page.
```typescript
import { Page } from "lume/core/file.ts";
site.process([".css"], (filteredPages, allPages) => {
for (const page of filteredPages) {
// Minify CSS
const { code, map } = myCssMinifier(page.text);
page.text = code;
// Create source map page
const pageMap = Page.create({
url: page.data.url + ".map",
content: map,
});
allPages.push(pageMap);
}
});
```
--------------------------------
### Lume: Event Listener Options (once)
Source: https://lume.land/docs/core/events
Example of using the `once: true` option to ensure an event listener is executed only a single time. This is useful for one-off setup tasks.
```javascript
site.addEventListener("afterUpdate", () => {
console.log("This is the first update");
}, {
once: true,
});
```
--------------------------------
### Deno Deploy Entrypoint Server Script
Source: https://lume.land/docs/advanced/deployment
A serve.ts file acting as the entrypoint for Deno Deploy, which starts a server to serve static files from the '_site' directory. It listens on port 8000.
```typescript
import Server from "lume/core/server.ts";
const server = new Server({
port: 8000,
root: `${Deno.cwd()}/_site`,
});
server.start();
console.log("Listening on http://localhost:8000");
```
--------------------------------
### Initialize Lume Project
Source: https://lume.land/docs/overview/command-line
Initializes a new Lume project in the current directory. This command runs a Deno script that sets up the necessary configuration files and directory structure for a Lume site. It can be executed using the Deno task or the installed Lume CLI.
```bash
deno task lume init
```
```bash
lume init
```
--------------------------------
### Lume File Structure Example
Source: https://lume.land/docs/creating-pages/page-files
Demonstrates how Lume maps Markdown files in the root directory to generated HTML files, including the default pretty URL behavior.
```plaintext
├── index.md => /index.html
├── about.md => /about/index.html
└── contact.md => /contact/index.html
```
--------------------------------
### Layout with Data and Content Placeholder (Vento)
Source: https://lume.land/docs/creating-pages/layouts
A more complex layout example using Vento, which includes front matter variables like `language` and `title`, and a placeholder for the page's `content`. It also specifies `layouts/main.vto` as a wrapper.
```html
---
title: Default page title
language: en
layout: layouts/main.vto
---
`;
}
```
--------------------------------
### TSX Page with Lume Data and Helpers
Source: https://lume.land/docs/configuration/using-typescript
An example of a TSX page component that utilizes the global `Lume.Data` and `Lume.Helpers` interfaces to access page data and formatting functions. This demonstrates basic usage within a Lume project.
```tsx
export default (data: Lume.Data, filters: Lume.Helpers) => {
const { title, date } = data;
return (
{title}
);
};
```
--------------------------------
### AWS Amplify Deployment Configuration (amplify.yml)
Source: https://lume.land/docs/advanced/deployment
Configuration file for deploying a Lume site using AWS Amplify. It specifies build commands, including Deno installation and execution, and the base directory for site artifacts. Ensure to ignore this file in your Lume config if not managed directly in the repository.
```yaml
version: 1
frontend:
phases:
build:
commands:
- curl -fsSL https://deno.land/x/install/install.sh | sh
- /root/.deno/bin/deno task build
artifacts:
baseDirectory: /_site
files:
- "**/*"
cache:
paths: []
```
--------------------------------
### Serve Site Locally on Custom Port
Source: https://lume.land/docs/overview/command-line
Starts a local web server on a specified port to preview the static site. This command allows customization of the default port (3000) for the development server, which also includes live-reloading capabilities. Useful for avoiding port conflicts or testing on specific network configurations.
```bash
deno task lume -s --port=8000
```
```bash
lume -s --port=8000
```
--------------------------------
### Manual Deployment Command using Deno Task
Source: https://context7.com/context7/lume_land/llms.txt
Executes the 'deploy' task defined in the Deno configuration, which builds the site and deploys it using rsync.
```bash
deno task deploy
```
--------------------------------
### Serve Site Locally with Live Reload
Source: https://lume.land/docs/overview/command-line
Starts a local web server to preview the static site and automatically reloads the browser when changes are detected. This is useful for development, allowing you to see updates in real-time. The server defaults to port 3000, but can be configured using the --port argument. Aliased by the 'serve' task.
```bash
deno task lume -s
```
```bash
lume -s
```
```bash
deno task serve
```
--------------------------------
### Build and Serve Lume Site
Source: https://context7.com/context7/lume_land/llms.txt
Commands to build the static site, serve it locally with live reloading, and manage Lume upgrades. These commands leverage Deno tasks defined in deno.json.
```bash
# Build the site (outputs to _site/)
denotask build
# Build with local server and live reload on port 3000
denotask serve
# Custom port
denotask lume -s --port=8000
# Watch for changes without server
denotask lume --watch
# Upgrade Lume to latest version
denotask lume upgrade
```
--------------------------------
### Create Open Source Plugin for Lume
Source: https://lume.land/docs/advanced/plugins
An example of a Lume plugin (`openSource`) that depends on another plugin (`cssBanner`) and invokes its hook (`changeCssBanner`) to set an 'open source' message. It includes error handling if the dependency is not met.
```typescript
// my-plugins/open_source.ts
export default function () {
return (site: Site) => {
if (!site.hooks.changeCssBanner) {
throw new Error("This plugin requires css_banner to be installed before");
}
site.hooks.changeCssBanner("This code is open source");
};
}
```
--------------------------------
### Add Files and Directories (Lume)
Source: https://lume.land/docs/configuration/add-files
Add files and directories to your Lume site. Paths are relative to the source directory. You can rename files or directories using the second argument. Files starting with `_` or `.` are ignored by default unless added explicitly.
```javascript
// Add all files in the "img" directory
site.add("img");
// Add the favicon file
site.add("favicon.ico");
// Add the "img" directory and rename it to "images"
site.add("img", "images");
// Add the "static-files/favicons/favicon.ico" renamed to "favicon.ico"
site.add("static-files/favicons/favicon.ico", "favicon.ico");
// Add content of "assets" directory to the root of your site
site.add("assets", ".");
// Ignore a subfolder
site.ignore("/files/pictures/");
// Add the /files/ folder.
// The subfolder /files/pictures/ is ignored,
// in addition to all files starting with . and _
site.add("/files/");
// Add an underscored file
site.add("_headers");
```
--------------------------------
### Lume Instantiation with Configuration Options
Source: https://lume.land/docs/advanced/cheatsheet
Demonstrates how to instantiate a Lume site with various configuration options. This includes source and destination paths, build settings, server configurations, watcher options, component settings, and plugin configurations. These options control the fundamental behavior of the Lume build process.
```javascript
const site = lume(
{
/** Where the site's source is stored */
src: "./",
/** Where the built site will go */
dest: "./_site",
/** Whether the destination folder (defined in `dest`) should be emptied before the build */
emptyDest: true,
/** The default includes path, relative to the `src` folder */
includes: "_includes",
/** The site location (used to generate final urls) */
location: new URL("http://localhost"),
/** Set true to generate pretty urls (`/about-me/`) */
prettyUrls: true,
/** Local server options(when using `lume --serve`) */
server: {
/** The port to listen on */
port: 3000,
/** Open the server in a browser after starting the server */
open: false,
/** The file to serve when getting a 404 error */
page404: "/404.html",
/** Optional middleware for the server */
middlewares: [];
},
/** Local file watcher options */
watcher: {
/** Paths to ignore */
ignore: [
"/.git",
(path) => path.endsWith("/.DS_Store"),
],
/** The interval in milliseconds to check for changes */
debounce: 100,
},
/** Component options */
components: {
/** The name of the file to save component css code to */
cssFile: "/style.css",
/** The name of the file to save component javascript code to */
jsFile: "/script.js",
/** Placeholder used to replace with the final content */
placeholder: ""
}
},
{
/** Options for the url plugin, which is loaded by default */
url: undefined,
/** Options for the json plugin, which is loaded by default */
json: undefined,
/** Options for the markdown plugin, which is loaded by default */
markdown: undefined,
/** Options for the modules plugin, which is loaded by default */
modules: undefined,
/** Options for the nunjucks plugin, which is loaded by default */
nunjucks: undefined,
/** Options for the search plugin, which is loaded by default */
search: undefined,
/** Options for the paginate plugin, which is loaded by default */
paginate: undefined,
/** Options for the yaml plugin, which is loaded by default */
yaml: undefined,
}
)
```
--------------------------------
### Deno Task Configuration for Building and Deploying
Source: https://context7.com/context7/lume_land/llms.txt
Configuration for Lume's build, serve, and deploy tasks using Deno. The 'deploy' task combines building the site and using rsync for manual deployment.
```json
{
"tasks": {
"build": "deno task lume",
"serve": "deno task lume -s",
"lume": "echo \"import 'lume/cli.ts'\" | deno run -A -",
"deploy": "deno task build && rsync -r _site/ user@my-site.com:~/www"
}
}
```
--------------------------------
### Create Basic Markdown Page (Lume)
Source: https://lume.land/docs/getting-started/your-first-page
This snippet demonstrates the content of a simple markdown file used with Lume. It includes basic markdown formatting and is intended to be placed in an `index.md` file within a Lume project.
```markdown
# Welcome to my website
This is my first page using **Lume,** a static site generator for Deno.
I hope you enjoy it.
```
--------------------------------
### Configure Vercel Deployment for Lume
Source: https://context7.com/context7/lume_land/llms.txt
This Bash snippet provides the necessary commands for deploying a Lume site to Vercel. It includes instructions for setting the build command and output directory within the Vercel dashboard.
```bash
# Build command in Vercel dashboard:
curl -fsSL https://deno.land/x/install/install.sh | sh && /vercel/.deno/bin/deno task build
# Output directory: _site
```
--------------------------------
### Modify HTML Content with DOM API in Lume
Source: https://lume.land/docs/advanced/the-data-model
This example demonstrates using the DOM API within Lume's processing stage to modify HTML content. It targets all anchor tags starting with 'http' and sets their 'target' attribute to '_blank', making them open in a new tab. This requires the page content to be parsed as a DOM document.
```javascript
site.process([".html"], (page) => {
// Get the DOM
const document = page.document;
// Modify the content
document.querySelectorAll('a[href^="http"]').forEach((link) => {
link.setAttribute("target", "_blank");
});
});
```
--------------------------------
### Configure GitHub Actions for Lume Deployment
Source: https://context7.com/context7/lume_land/llms.txt
This YAML configuration sets up a GitHub Actions workflow to automatically build and deploy a Lume static site to GitHub Pages upon pushing to the `main` branch. It includes steps for checking out code, setting up Deno, building the site, and uploading artifacts.
```yaml
# .github/workflows/publish.yml
name: Publish on GitHub Pages
on:
push:
branches: [main]
permissions:
contents: read
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Setup Deno environment
uses: denoland/setup-deno@v2
with:
cache: true
- name: Build site
run: deno task build
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: "_site"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
```
--------------------------------
### Generate Pages with Layouts (JavaScript)
Source: https://lume.land/docs/core/multiple-pages
This example demonstrates generating pages that utilize a specified layout. Each yielded page object includes a 'layout' property along with other data like 'title' and 'body' to be used within the layout. This approach simplifies content structure when multiple pages share the same template.
```javascript
export default function* () {
yield {
url: "/page-1/",
layout: "layouts/article.vto",
title: "Article 1",
body: "Welcome to the article 1",
};
yield {
url: "/page-2/",
layout: "layouts/article.vto",
title: "Article 2",
body: "Welcome to the article 2",
};
yield {
url: "/page-3/",
layout: "layouts/article.vto",
title: "Article 3",
body: "Welcome to the article 3",
};
}
```
--------------------------------
### Configure Netlify Deployment for Lume
Source: https://context7.com/context7/lume_land/llms.txt
This TOML configuration file specifies the build settings for deploying a Lume site to Netlify. It defines the output directory (`publish`) and the build command (`command`).
```toml
# netlify.toml
[build]
publish = "_site"
command = "deno task build"
```
--------------------------------
### Accessing Shared Data in JSX Template
Source: https://lume.land/docs/creating-pages/shared-data
Example of how to map over and display shared data (documents) within a JSX template (`.jsx`).
```jsx
export default function ({ documents }) {
return (
<>
Documents
{documents.map((doc) =>
{doc.title}
)}
>
);
}
```
--------------------------------
### Create a Server for Deno Deploy with Lume
Source: https://context7.com/context7/lume_land/llms.txt
This TypeScript code sets up a basic HTTP server using Lume's `Server` class, configured to serve static files from the `_site` directory. This is suitable for deployment on platforms like Deno Deploy.
```typescript
// serve.ts
import Server from "lume/core/server.ts";
const server = new Server({
port: 8000,
root: `${Deno.cwd()}/_site`,
});
server.start();
console.log("Listening on http://localhost:8000");
```
--------------------------------
### Accessing Shared Data in Nunjucks Template
Source: https://lume.land/docs/creating-pages/shared-data
Example of how to iterate over and display shared data (documents) within a Nunjucks template (`.vto`).
```nunjucks
Documents
{{ for doc of documents }}
{{ doc.title }}
{{ /for }}
```
--------------------------------
### Create a Title Component (TSX)
Source: https://lume.land/docs/core/components
An example of a simple title component written in TSX. It accepts `children` and renders them within an `
` tag.
```tsx
// _components/title.tsx
export default function title({ children }) {
return
{children}
;
}
```
--------------------------------
### Static Data in _data.json
Source: https://lume.land/docs/creating-pages/shared-data
Example of defining static shared data using a JSON file. This data is directly embedded and accessible by pages.
```json
{
"people": [
{
"name": "Oscar Otero",
"color": "black"
},
{
"name": "Laura Rubio",
"color": "blue"
}
]
}
```
--------------------------------
### Automated Deployment to Deno Deploy using GitHub Actions
Source: https://context7.com/context7/lume_land/llms.txt
This workflow automates the build and deployment of a Lume site to Deno Deploy on every push to the main branch. It requires Deno and DeployCTL to be set up.
```yaml
name: Publish on Deno Deploy
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Setup Deno environment
uses: denoland/setup-deno@v2
- name: Build site
run: deno task build
- name: Deploy to Deno Deploy
uses: denoland/deployctl@v1
with:
project: project-name
import-map: "./deno.json"
entrypoint: serve.ts
```
--------------------------------
### Lume: Event Listener Options (signal)
Source: https://lume.land/docs/core/events
Example of using an `AbortSignal` to control the lifecycle of an event listener. The listener is removed automatically when the `AbortController` signals it.
```javascript
const controller = new AbortController();
let times = 0;
site.addEventListener("afterUpdate", () => {
times++;
// Remove the listener after 5 times
if (times === 5) {
controller.abort();
}
console.log(`This is the update ${times}`);
}, {
signal: controller.signal,
});
```
--------------------------------
### Static Data in _data.yml
Source: https://lume.land/docs/creating-pages/shared-data
Example of defining static shared data using a YAML file. YAML is often more human-readable for configuration and data structures.
```yaml
people:
- name: Oscar Otero
color: black
- name: Laura Rubio
color: blue
```
--------------------------------
### Configure Asset File Loading in Lume
Source: https://lume.land/docs/core/concepts
Set up Lume to handle specific file extensions or directories as asset pages. Asset pages are processed and saved directly to the 'dest' folder without rendering. Use `site.add()` to specify which extensions or directories should be treated as assets.
```javascript
// Add .css files
site.add([".css"]);
// Add all files from the "/static/" directory
site.add("static");
```
--------------------------------
### Create JSON File with JavaScript Archetype
Source: https://lume.land/docs/core/archetypes
This example demonstrates creating a JSON file. Lume automatically converts an object to a JSON string when the `path` has a `.json` extension.
```javascript
// Archetype/pages/example.json
export default function () {
return {
path: "/pages/example.json",
content: {
title: "Title content",
content: "Page content",
},
};
}
```
--------------------------------
### Show Lume CLI Help
Source: https://lume.land/docs/overview/command-line
Displays all available commands and options for the Lume CLI. This is a standard help command that provides an overview of the CLI's capabilities and usage. It's useful for discovering features or recalling specific command syntax.
```bash
deno task lume -h
```
--------------------------------
### Dynamic Data in _data.ts
Source: https://lume.land/docs/creating-pages/shared-data
Example of defining dynamic shared data using a TypeScript file. This allows fetching data from external sources like databases or APIs.
```typescript
import { db } from "./database.ts";
const people = db.query("select name, color from people");
export { people };
```
--------------------------------
### Disable Slugify URLs for Copied Files
Source: https://lume.land/docs/advanced/migrate-to-lume2
Modify the `slugify_urls` plugin to prevent it from slugifying files copied using `site.copy()`. This example shows how to limit slugification to HTML files.
```javascript
site.use(slugifyUrls({
extensions: [".html"], // To slugify only HTML pages
}));
```
--------------------------------
### Create Pages with Vento - Lume
Source: https://lume.land/docs/getting-started/page-formats
This snippet demonstrates creating a page using the Vento templating engine. It includes front matter for metadata and Vento syntax for dynamic content rendering. The rendered output is passed to a layout if specified.
```Vento
---
title: Welcome to my page
layout: layout.vto
links:
- text: My Twitter
url: https://twitter.com/misteroom
- text: My GitHub profile
url: https://github.com/oscarotero
---
```
--------------------------------
### Create a Vento Layout for Lume
Source: https://lume.land/docs/getting-started/create-a-layout
This Vento template (`layout.vto`) defines the complete HTML structure for a web page. It includes essential tags and uses `{{ content }}` as a placeholder for page-specific content.
```html
My first page
{{ content }}
```
--------------------------------
### Initialize Lume Site Instance
Source: https://lume.land/docs/configuration/config-file
This snippet demonstrates the minimal required code to initialize a Lume site instance using the `lume()` function. It imports the necessary module and exports the created site object.
```typescript
import lume from "lume/mod.ts";
const site = lume();
export default site;
```
--------------------------------
### Assign Layout to Markdown Page using Front Matter
Source: https://lume.land/docs/getting-started/create-a-layout
This Markdown file (`index.md`) demonstrates how to assign a layout using front matter. The `layout: layout.vto` directive tells Lume to use the specified Vento file for rendering.
```markdown
---
layout: layout.vto
---
# Welcome to my website
This is my first page using **Lume,**
a static site generator for Deno.
I hope you enjoy it.
```
--------------------------------
### Second Page Front Matter (with shared data)
Source: https://lume.land/docs/getting-started/shared-data
Example of a second page's front matter. Similar to the index page, the `layout` variable is automatically applied due to the `_data.yml` file.
```markdown
---
title: My second page
---
# Another page
My second page in **Lume**.
This is getting better!
```
--------------------------------
### Index Page Front Matter (with shared data)
Source: https://lume.land/docs/getting-started/shared-data
Example of an index page's front matter. With `_data.yml` in place, the `layout` variable doesn't need to be explicitly defined here, as it's inherited.
```markdown
---
title: This is my website
---
# Welcome to my website
This is my first page using **Lume,**
a static site generator for Deno.
I hope you enjoy it.
```
--------------------------------
### Run Lume Scripts from CLI
Source: https://context7.com/context7/lume_land/llms.txt
This Bash snippet shows how to execute custom Lume task runners directly from the command line using `deno task lume run` followed by the script name.
```bash
# From CLI
den
o task lume run deploy
den
o task lume run save-site
```
--------------------------------
### Add Hook to Change CSS Banner Message in Lume Plugin
Source: https://lume.land/docs/advanced/plugins
Extends the CSS banner plugin to include a hook (`changeCssBanner`) that allows modifying the banner message after the plugin has been installed. This enables dynamic customization.
```typescript
// my-plugins/css_banner.ts
interface Options {
message: string;
}
export default function (options: Options) {
function addBanner(content: string): string {
const banner = `/* ${options.message} */`;
return banner + "\n" + content;
}
return (site: Site) => {
// Add a hook to change the message
site.hooks.changeCssBanner = (message: string) => {
options.message = message;
};
site.process([".css"], (pages) => {
for (const page of pages) {
page.text = addBanner(page.text);
}
});
};
}
```
--------------------------------
### Nest Components in Vento (Practical Method)
Source: https://lume.land/docs/core/components
Shows the practical way to nest components in Vento using the `comp` special tag, similar to JSX syntax, allowing for cleaner nesting of child content.
```vento
{{ comp container }}
Content of the Container component
{{ comp button }}
This is a button inside the Container component
{{ /comp }}
{{ /comp }}
```
--------------------------------
### Apply Global Processors to All Pages in Lume
Source: https://context7.com/context7/lume_land/llms.txt
Processors can be configured to run on all pages, regardless of their file extension, by using a wildcard character '*' or by omitting the file extension argument.
```typescript
// Process all pages regardless of extension
site.process("*", processAllPages);
// Alternative syntax
site.process(processAllPages);
```
--------------------------------
### Define Lume Script with Custom JavaScript Function
Source: https://lume.land/docs/core/scripts
This example demonstrates how to use a custom JavaScript function as a Lume script. The function is executed directly when the script is run, allowing for programmatic control over file operations and other logic.
```javascript
site.script("add-date-published", () => {
Deno.writeTextFileSync(
site.dest("published.txt"),
`Site published at: ${Date.now()}`,
);
});
```
--------------------------------
### Deno Task for Manual rsync Deployment
Source: https://lume.land/docs/advanced/deployment
Defines a 'deploy' task in deno.json for building a Lume site and deploying it using rsync. Assumes a local build output in the '_site' directory.
```json
{
"importMap": "import_map.json",
"tasks": {
"build": "deno task lume",
"serve": "deno task lume -s",
"lume": "echo \"import 'lume/cli.ts'\" | deno run -A -",
"deploy": "deno task build && rsync -r _site/ user@my-site.com:~/www"
}
}
```
--------------------------------
### Importing Lume Utilities (Lume Specifier)
Source: https://lume.land/docs/advanced/plugins
This code snippet shows the recommended way to import Lume utilities using the 'lume/' specifier. This approach helps avoid loading multiple versions of Lume by leveraging configured import maps.
```typescript
import { merge } from "lume/core/utils/object.ts";
```
--------------------------------
### Enable Auto Open Browser
Source: https://lume.land/docs/configuration/config-file
Automatically opens the generated site in the default web browser once the local server starts. This can also be controlled via CLI flags `--open` or `-o`.
```typescript
const site = lume({
server: {
open: true,
},
});
```