diff --git a/README_BOOK_CATALOG.md b/README_BOOK_CATALOG.md new file mode 100644 index 0000000..825be1b --- /dev/null +++ b/README_BOOK_CATALOG.md @@ -0,0 +1,155 @@ +# Book Catalog Example + +A complete example demonstrating the nginx-test SQLite module with a read-only book catalog. + +## Features + +- **SQLite Database**: Stores book information (title, author, ISBN, year, genre, description, rating) +- **Multiple Views**: Different locations for browsing by category +- **Template Inheritance**: Global templates (header, footer, book_card) shared across all pages +- **Local Templates**: Category-specific styling and layouts +- **Responsive Design**: Modern, gradient-styled UI + +## Setup + +### 1. Create and populate the database + +```bash +chmod +x setup_book_catalog.sh +./setup_book_catalog.sh +``` + +This creates `book_catalog.db` with 10 sample technical books across three genres: +- Programming +- Databases +- Computer Science + +### 2. Build the module + +```bash +direnv exec "$PWD" cargo build +``` + +### 3. Start nginx + +```bash +./ngx_src/nginx-1.28.0/objs/nginx -c conf/book_catalog.conf -p . +``` + +### 4. Visit the catalog + +Open your browser to: +- http://localhost:8080/ (redirects to all books) +- http://localhost:8080/books/all +- http://localhost:8080/books/programming +- http://localhost:8080/books/databases +- http://localhost:8080/books/computer-science + +### 5. Stop nginx + +```bash +./ngx_src/nginx-1.28.0/objs/nginx -s stop -c conf/book_catalog.conf -p . +``` + +## Directory Structure + +``` +nginx-test/ +├── book_catalog.db # SQLite database +├── setup_book_catalog.sh # Database setup script +├── conf/ +│ └── book_catalog.conf # Nginx configuration +└── server_root/ + ├── global_templates/ # Shared templates + │ ├── header.hbs # Page header with navigation + │ ├── footer.hbs # Page footer + │ └── book_card.hbs # Reusable book card partial + └── books/ + ├── all/ + │ └── list.hbs # All books page + ├── programming/ + │ └── list.hbs # Programming books page + ├── databases/ + │ └── list.hbs # Database books page + └── computer-science/ + └── list.hbs # CS books page +``` + +## How It Works + +### Template Loading Order + +For each request, the module: + +1. **Loads global templates** from `server_root/global_templates/`: + - `header.hbs` - Page structure and navigation + - `footer.hbs` - Page footer + - `book_card.hbs` - Book display component + +2. **Loads local templates** from the location's directory: + - Each category has its own `list.hbs` with custom styling + - Local templates can override global ones + +3. **Renders the main template** with SQL query results + +### Template Usage + +**In list.hbs:** +```handlebars +{{> header}} + +
Book Collection
+Top Rated
+Browse All
+Fundamental concepts, algorithms, and theoretical computer science
+No computer science books found.
+{{/unless}} + +{{> footer}} + diff --git a/server_root/books/databases/list.hbs b/server_root/books/databases/list.hbs new file mode 100644 index 0000000..a8aad8b --- /dev/null +++ b/server_root/books/databases/list.hbs @@ -0,0 +1,107 @@ +{{> header}} + + + +Deep dive into database systems, design, and data management
+No database books found.
+{{/unless}} + +{{> footer}} + diff --git a/server_root/books/programming/list.hbs b/server_root/books/programming/list.hbs new file mode 100644 index 0000000..4c6ce74 --- /dev/null +++ b/server_root/books/programming/list.hbs @@ -0,0 +1,107 @@ +{{> header}} + + + +Books focused on programming languages, practices, and software development
+No programming books found.
+{{/unless}} + +{{> footer}} + diff --git a/server_root/global_templates/book_card.hbs b/server_root/global_templates/book_card.hbs new file mode 100644 index 0000000..fcb32de --- /dev/null +++ b/server_root/global_templates/book_card.hbs @@ -0,0 +1,16 @@ +{{description}}
+