2
3// Simple template engine for processing Nunjucks-like templates
4function processTemplate(template: string, data: any): string {
5 let result = template;
6
39}
40
41function getNestedValue(obj: any, path: string): any {
42 return path.split('.').reduce((current, key) => {
43 if (current && typeof current === 'object') {
48}
49
50function evaluateCondition(condition: string, data: any): boolean {
51 // Simple condition evaluation - just check if variable exists and is truthy
52 const value = getNestedValue(data, condition);
164};
165
166function formatDate(date: Date): string {
167 return date.toLocaleDateString('en-US', {
168 year: 'numeric',
172}
173
174export default async function(req: Request): Promise<Response> {
175 const url = new URL(req.url);
176 const path = url.pathname;
1const { DateTime } = require("luxon");
2
3module.exports = function(eleventyConfig) {
4 // Copy static assets
5 eleventyConfig.addPassthroughCopy("src/css");
33
34 // Create a collection for blog posts
35 eleventyConfig.addCollection("posts", function(collectionApi) {
36 return collectionApi.getFilteredByGlob("src/posts/*.md").sort((a, b) => {
37 return b.date - a.date; // Sort by date descending
40
41 // Create a collection for featured posts
42 eleventyConfig.addCollection("featuredPosts", function(collectionApi) {
43 return collectionApi.getFilteredByGlob("src/posts/*.md")
44 .filter(post => post.data.featured)
29```javascript
30// In .eleventy.js
31eleventyConfig.addCollection("posts", function(collectionApi) {
32 return collectionApi.getFilteredByGlob("src/posts/*.md");
33});
97.token.atrule,
98.token.attr-value,
99.token.function,
100.token.class-name {
101 color: #e6db74;
50Block code:
51```javascript
52function greet(name) {
53 return `Hello, ${name}!`;
54}
29```javascript
30// In .eleventy.js
31eleventyConfig.addCollection("posts", function(collectionApi) {
32 return collectionApi.getFilteredByGlob("src/posts/*.md");
33});
44```javascript
45// Here's some sample code with syntax highlighting
46function welcomeMessage(name) {
47 return `Welcome to the blog, ${name}!`;
48}
3import type { User, Session } from "../../shared/types.ts";
4
5export async function authenticateUser(username: string, password: string): Promise<User | null> {
6 const passwordHash = await hashPassword(password);
7
34}
35
36export async function createSession(userId: number, username: string): Promise<string> {
37 const sessionId = crypto.randomUUID();
38 const expiresAt = new Date();
47}
48
49export async function validateSession(sessionId: string): Promise<Session | null> {
50 const result = await sqlite.execute(
51 `SELECT id, user_id, username, created_at, expires_at FROM ${SESSIONS_TABLE}
68}
69
70export async function deleteSession(sessionId: string): Promise<void> {
71 await sqlite.execute(
72 `DELETE FROM ${SESSIONS_TABLE} WHERE id = ?`,
75}
76
77export async function getUserById(userId: number): Promise<User | null> {
78 const result = await sqlite.execute(
79 `SELECT id, username, email, created_at, last_login FROM ${USERS_TABLE} WHERE id = ?`,
12}
13
14function App() {
15 const [state, setState] = useState<AppState>({
16 isAuthenticated: false,
8}
9
10export default function Dashboard({ user, onLogout }: DashboardProps) {
11 const handleLogout = async () => {
12 try {
A helper function to build a file's email
Simple functional CSS library for Val Town
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.