From 7eee5481c513b16b75d4b77b27643d6533dfe83c Mon Sep 17 00:00:00 2001 From: Oshadha Gunawardena Date: Fri, 10 Apr 2026 11:30:05 +0530 Subject: [PATCH 1/3] Add initial project structure with default files for Zola site - Introduced .gitignore, README.md, and initial content files. - Added base, index, page, and section templates for rendering. - Included a default style.css for basic styling. - Updated tests to verify the creation of new files and directories. --- src/cmd/init.rs | 225 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) diff --git a/src/cmd/init.rs b/src/cmd/init.rs index b137bdab0..d603a309e 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -25,6 +25,201 @@ theme = "catppuccin-mocha" # Put all your custom variables here "#; +const GITIGNORE: &str = r#"public/ +.DS_Store +"#; + +const README: &str = r#"# My Zola Site + +This site is built with [Zola](https://www.getzola.org/). + +## Getting Started + +```bash +# Serve the site locally +zola serve + +# Build for production +zola build +``` + +## Documentation + +Visit [https://www.getzola.org/documentation](https://www.getzola.org/documentation) for full documentation. +"#; + +const INDEX_CONTENT: &str = r#"+++ +title = "Home" ++++ + +Welcome to your new Zola site! +"#; + +const BASE_TEMPLATE: &str = r#" + + + + + {% block title %}{{ config.title }}{% endblock %} + + + +
+ +
+
+ {% block content %}{% endblock %} +
+ + + +"#; + +const INDEX_TEMPLATE: &str = r#"{% extends "base.html" %} + +{% block content %} +

{{ section.title }}

+{{ section.content | safe }} +{% endblock %} +"#; + +const PAGE_TEMPLATE: &str = r#"{% extends "base.html" %} + +{% block title %}{{ page.title }} | {{ config.title }}{% endblock %} + +{% block content %} +
+

{{ page.title }}

+ {{ page.content | safe }} +
+{% endblock %} +"#; + +const SECTION_TEMPLATE: &str = r#"{% extends "base.html" %} + +{% block title %}{{ section.title }} | {{ config.title }}{% endblock %} + +{% block content %} +

{{ section.title }}

+{{ section.content | safe }} + +{% if section.pages %} + +{% endif %} +{% endblock %} +"#; + +const STYLE_CSS: &str = r#"/* Reset and base styles */ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; + line-height: 1.6; + color: #333; + background: #fff; + max-width: 720px; + margin: 0 auto; + padding: 1.5rem; +} + +/* Typography */ +h1, h2, h3, h4, h5, h6 { + margin-top: 1.5rem; + margin-bottom: 0.75rem; + line-height: 1.2; +} + +h1 { font-size: 2rem; } +h2 { font-size: 1.5rem; } +h3 { font-size: 1.25rem; } + +p { + margin-bottom: 1rem; +} + +/* Links */ +a { + color: #0066cc; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +/* Header */ +header { + margin-bottom: 3rem; + padding-bottom: 1rem; + border-bottom: 1px solid #ddd; +} + +nav a { + margin-right: 1rem; +} + +/* Main content */ +main { + min-height: 60vh; +} + +article { + margin-bottom: 2rem; +} + +/* Lists */ +ul, ol { + margin-left: 1.5rem; + margin-bottom: 1rem; +} + +li { + margin-bottom: 0.25rem; +} + +/* Footer */ +footer { + margin-top: 3rem; + padding-top: 1.5rem; + border-top: 1px solid #ddd; + color: #666; + font-size: 0.9rem; +} + +/* Code */ +code { + background: #f4f4f4; + padding: 0.2rem 0.4rem; + border-radius: 3px; + font-size: 0.9em; +} + +pre { + background: #f4f4f4; + padding: 1rem; + border-radius: 3px; + overflow-x: auto; + margin-bottom: 1rem; +} + +pre code { + background: none; + padding: 0; +} +"#; + // canonicalize(path) function on windows system returns a path with UNC. // Example: \\?\C:\Users\VssAdministrator\AppData\Local\Temp\new_project // More details on Universal Naming Convention (UNC): @@ -112,11 +307,25 @@ fn populate(path: &Path, compile_sass: bool, config: &str) -> Result<()> { if !path.exists() { fs::create_dir(path)?; } + create_file(&path.join("zola.toml"), config)?; + create_file(&path.join(".gitignore"), GITIGNORE)?; + create_file(&path.join("README.md"), README)?; + fs::create_dir(path.join("content"))?; + create_file(&path.join("content/_index.md"), INDEX_CONTENT)?; + fs::create_dir(path.join("templates"))?; + create_file(&path.join("templates/base.html"), BASE_TEMPLATE)?; + create_file(&path.join("templates/index.html"), INDEX_TEMPLATE)?; + create_file(&path.join("templates/page.html"), PAGE_TEMPLATE)?; + create_file(&path.join("templates/section.html"), SECTION_TEMPLATE)?; + fs::create_dir(path.join("static"))?; + create_file(&path.join("static/style.css"), STYLE_CSS)?; + fs::create_dir(path.join("themes"))?; + if compile_sass { fs::create_dir(path.join("sass"))?; } @@ -192,9 +401,17 @@ mod tests { populate(&dir, true, "").expect("Could not populate zola directories"); assert!(dir.join("zola.toml").exists()); + assert!(dir.join(".gitignore").exists()); + assert!(dir.join("README.md").exists()); assert!(dir.join("content").exists()); + assert!(dir.join("content/_index.md").exists()); assert!(dir.join("templates").exists()); + assert!(dir.join("templates/base.html").exists()); + assert!(dir.join("templates/index.html").exists()); + assert!(dir.join("templates/page.html").exists()); + assert!(dir.join("templates/section.html").exists()); assert!(dir.join("static").exists()); + assert!(dir.join("static/style.css").exists()); assert!(dir.join("themes").exists()); assert!(dir.join("sass").exists()); @@ -212,9 +429,17 @@ mod tests { assert!(dir.exists()); assert!(dir.join("zola.toml").exists()); + assert!(dir.join(".gitignore").exists()); + assert!(dir.join("README.md").exists()); assert!(dir.join("content").exists()); + assert!(dir.join("content/_index.md").exists()); assert!(dir.join("templates").exists()); + assert!(dir.join("templates/base.html").exists()); + assert!(dir.join("templates/index.html").exists()); + assert!(dir.join("templates/page.html").exists()); + assert!(dir.join("templates/section.html").exists()); assert!(dir.join("static").exists()); + assert!(dir.join("static/style.css").exists()); assert!(dir.join("themes").exists()); assert!(dir.join("sass").exists()); From 40c0088681cae898bf8da8cadb06881505364454 Mon Sep 17 00:00:00 2001 From: Oshadha Gunawardena Date: Fri, 10 Apr 2026 17:59:00 +0530 Subject: [PATCH 2/3] Refactor default theme files for Zola site - Replaced hardcoded content in init.rs with includes for default theme files. - Added .gitignore, README.md, and initial content files for the default theme. - Introduced base, index, page, and section templates for rendering. - Included a default style.css for basic styling. --- src/cmd/default_theme/.gitignore | 2 + src/cmd/default_theme/README.md | 17 ++ src/cmd/default_theme/content/_index.md | 5 + src/cmd/default_theme/static/style.css | 101 ++++++++++ src/cmd/default_theme/templates/base.html | 22 ++ src/cmd/default_theme/templates/index.html | 6 + src/cmd/default_theme/templates/page.html | 10 + src/cmd/default_theme/templates/section.html | 16 ++ src/cmd/init.rs | 202 +------------------ 9 files changed, 187 insertions(+), 194 deletions(-) create mode 100644 src/cmd/default_theme/.gitignore create mode 100644 src/cmd/default_theme/README.md create mode 100644 src/cmd/default_theme/content/_index.md create mode 100644 src/cmd/default_theme/static/style.css create mode 100644 src/cmd/default_theme/templates/base.html create mode 100644 src/cmd/default_theme/templates/index.html create mode 100644 src/cmd/default_theme/templates/page.html create mode 100644 src/cmd/default_theme/templates/section.html diff --git a/src/cmd/default_theme/.gitignore b/src/cmd/default_theme/.gitignore new file mode 100644 index 000000000..0c376eaec --- /dev/null +++ b/src/cmd/default_theme/.gitignore @@ -0,0 +1,2 @@ +public/ +.DS_Store diff --git a/src/cmd/default_theme/README.md b/src/cmd/default_theme/README.md new file mode 100644 index 000000000..5a42eaa3a --- /dev/null +++ b/src/cmd/default_theme/README.md @@ -0,0 +1,17 @@ +# My Zola Site + +This site is built with [Zola](https://www.getzola.org/). + +## Getting Started + +```bash +# Serve the site locally +zola serve + +# Build for production +zola build +``` + +## Documentation + +Visit [https://www.getzola.org/documentation](https://www.getzola.org/documentation) for full documentation. diff --git a/src/cmd/default_theme/content/_index.md b/src/cmd/default_theme/content/_index.md new file mode 100644 index 000000000..4477221b7 --- /dev/null +++ b/src/cmd/default_theme/content/_index.md @@ -0,0 +1,5 @@ ++++ +title = "Home" ++++ + +Welcome to your new Zola site! diff --git a/src/cmd/default_theme/static/style.css b/src/cmd/default_theme/static/style.css new file mode 100644 index 000000000..f31ac5e8a --- /dev/null +++ b/src/cmd/default_theme/static/style.css @@ -0,0 +1,101 @@ +/* Reset and base styles */ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; + line-height: 1.6; + color: #333; + background: #fff; + max-width: 720px; + margin: 0 auto; + padding: 1.5rem; +} + +/* Typography */ +h1, h2, h3, h4, h5, h6 { + margin-top: 1.5rem; + margin-bottom: 0.75rem; + line-height: 1.2; +} + +h1 { font-size: 2rem; } +h2 { font-size: 1.5rem; } +h3 { font-size: 1.25rem; } + +p { + margin-bottom: 1rem; +} + +/* Links */ +a { + color: #0066cc; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +/* Header */ +header { + margin-bottom: 3rem; + padding-bottom: 1rem; + border-bottom: 1px solid #ddd; +} + +nav a { + margin-right: 1rem; +} + +/* Main content */ +main { + min-height: 60vh; +} + +article { + margin-bottom: 2rem; +} + +/* Lists */ +ul, ol { + margin-left: 1.5rem; + margin-bottom: 1rem; +} + +li { + margin-bottom: 0.25rem; +} + +/* Footer */ +footer { + margin-top: 3rem; + padding-top: 1.5rem; + border-top: 1px solid #ddd; + color: #666; + font-size: 0.9rem; +} + +/* Code */ +code { + background: #f4f4f4; + padding: 0.2rem 0.4rem; + border-radius: 3px; + font-size: 0.9em; +} + +pre { + background: #f4f4f4; + padding: 1rem; + border-radius: 3px; + overflow-x: auto; + margin-bottom: 1rem; +} + +pre code { + background: none; + padding: 0; +} diff --git a/src/cmd/default_theme/templates/base.html b/src/cmd/default_theme/templates/base.html new file mode 100644 index 000000000..a79491e7b --- /dev/null +++ b/src/cmd/default_theme/templates/base.html @@ -0,0 +1,22 @@ + + + + + + {% block title %}{{ config.title }}{% endblock %} + + + +
+ +
+
+ {% block content %}{% endblock %} +
+
+

Powered by Zola

+
+ + diff --git a/src/cmd/default_theme/templates/index.html b/src/cmd/default_theme/templates/index.html new file mode 100644 index 000000000..75c1ee1a6 --- /dev/null +++ b/src/cmd/default_theme/templates/index.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} + +{% block content %} +

{{ section.title }}

+{{ section.content | safe }} +{% endblock %} diff --git a/src/cmd/default_theme/templates/page.html b/src/cmd/default_theme/templates/page.html new file mode 100644 index 000000000..d73bcbbe9 --- /dev/null +++ b/src/cmd/default_theme/templates/page.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block title %}{{ page.title }} | {{ config.title }}{% endblock %} + +{% block content %} +
+

{{ page.title }}

+ {{ page.content | safe }} +
+{% endblock %} diff --git a/src/cmd/default_theme/templates/section.html b/src/cmd/default_theme/templates/section.html new file mode 100644 index 000000000..010ed5d4a --- /dev/null +++ b/src/cmd/default_theme/templates/section.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %}{{ section.title }} | {{ config.title }}{% endblock %} + +{% block content %} +

{{ section.title }}

+{{ section.content | safe }} + +{% if section.pages %} + +{% endif %} +{% endblock %} diff --git a/src/cmd/init.rs b/src/cmd/init.rs index d603a309e..133c51f6a 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -25,200 +25,14 @@ theme = "catppuccin-mocha" # Put all your custom variables here "#; -const GITIGNORE: &str = r#"public/ -.DS_Store -"#; - -const README: &str = r#"# My Zola Site - -This site is built with [Zola](https://www.getzola.org/). - -## Getting Started - -```bash -# Serve the site locally -zola serve - -# Build for production -zola build -``` - -## Documentation - -Visit [https://www.getzola.org/documentation](https://www.getzola.org/documentation) for full documentation. -"#; - -const INDEX_CONTENT: &str = r#"+++ -title = "Home" -+++ - -Welcome to your new Zola site! -"#; - -const BASE_TEMPLATE: &str = r#" - - - - - {% block title %}{{ config.title }}{% endblock %} - - - -
- -
-
- {% block content %}{% endblock %} -
-
-

Powered by Zola

-
- - -"#; - -const INDEX_TEMPLATE: &str = r#"{% extends "base.html" %} - -{% block content %} -

{{ section.title }}

-{{ section.content | safe }} -{% endblock %} -"#; - -const PAGE_TEMPLATE: &str = r#"{% extends "base.html" %} - -{% block title %}{{ page.title }} | {{ config.title }}{% endblock %} - -{% block content %} -
-

{{ page.title }}

- {{ page.content | safe }} -
-{% endblock %} -"#; - -const SECTION_TEMPLATE: &str = r#"{% extends "base.html" %} - -{% block title %}{{ section.title }} | {{ config.title }}{% endblock %} - -{% block content %} -

{{ section.title }}

-{{ section.content | safe }} - -{% if section.pages %} - -{% endif %} -{% endblock %} -"#; - -const STYLE_CSS: &str = r#"/* Reset and base styles */ -* { - margin: 0; - padding: 0; - box-sizing: border-box; -} - -body { - font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; - line-height: 1.6; - color: #333; - background: #fff; - max-width: 720px; - margin: 0 auto; - padding: 1.5rem; -} - -/* Typography */ -h1, h2, h3, h4, h5, h6 { - margin-top: 1.5rem; - margin-bottom: 0.75rem; - line-height: 1.2; -} - -h1 { font-size: 2rem; } -h2 { font-size: 1.5rem; } -h3 { font-size: 1.25rem; } - -p { - margin-bottom: 1rem; -} - -/* Links */ -a { - color: #0066cc; - text-decoration: none; -} - -a:hover { - text-decoration: underline; -} - -/* Header */ -header { - margin-bottom: 3rem; - padding-bottom: 1rem; - border-bottom: 1px solid #ddd; -} - -nav a { - margin-right: 1rem; -} - -/* Main content */ -main { - min-height: 60vh; -} - -article { - margin-bottom: 2rem; -} - -/* Lists */ -ul, ol { - margin-left: 1.5rem; - margin-bottom: 1rem; -} - -li { - margin-bottom: 0.25rem; -} - -/* Footer */ -footer { - margin-top: 3rem; - padding-top: 1.5rem; - border-top: 1px solid #ddd; - color: #666; - font-size: 0.9rem; -} - -/* Code */ -code { - background: #f4f4f4; - padding: 0.2rem 0.4rem; - border-radius: 3px; - font-size: 0.9em; -} - -pre { - background: #f4f4f4; - padding: 1rem; - border-radius: 3px; - overflow-x: auto; - margin-bottom: 1rem; -} - -pre code { - background: none; - padding: 0; -} -"#; +const GITIGNORE: &str = include_str!("default_theme/.gitignore"); +const README: &str = include_str!("default_theme/README.md"); +const INDEX_CONTENT: &str = include_str!("default_theme/content/_index.md"); +const BASE_TEMPLATE: &str = include_str!("default_theme/templates/base.html"); +const INDEX_TEMPLATE: &str = include_str!("default_theme/templates/index.html"); +const PAGE_TEMPLATE: &str = include_str!("default_theme/templates/page.html"); +const SECTION_TEMPLATE: &str = include_str!("default_theme/templates/section.html"); +const STYLE_CSS: &str = include_str!("default_theme/static/style.css"); // canonicalize(path) function on windows system returns a path with UNC. // Example: \\?\C:\Users\VssAdministrator\AppData\Local\Temp\new_project From caeb8031393cb19356d7d992b3905726b3ff3dd5 Mon Sep 17 00:00:00 2001 From: Oshadha Gunawardena Date: Sun, 26 Apr 2026 16:46:38 +0530 Subject: [PATCH 3/3] Tidy up spacing in init.rs with no functional changes. --- src/cmd/init.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cmd/init.rs b/src/cmd/init.rs index 133c51f6a..4283ea0b9 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -121,25 +121,25 @@ fn populate(path: &Path, compile_sass: bool, config: &str) -> Result<()> { if !path.exists() { fs::create_dir(path)?; } - + create_file(&path.join("zola.toml"), config)?; create_file(&path.join(".gitignore"), GITIGNORE)?; create_file(&path.join("README.md"), README)?; - + fs::create_dir(path.join("content"))?; create_file(&path.join("content/_index.md"), INDEX_CONTENT)?; - + fs::create_dir(path.join("templates"))?; create_file(&path.join("templates/base.html"), BASE_TEMPLATE)?; create_file(&path.join("templates/index.html"), INDEX_TEMPLATE)?; create_file(&path.join("templates/page.html"), PAGE_TEMPLATE)?; create_file(&path.join("templates/section.html"), SECTION_TEMPLATE)?; - + fs::create_dir(path.join("static"))?; create_file(&path.join("static/style.css"), STYLE_CSS)?; - + fs::create_dir(path.join("themes"))?; - + if compile_sass { fs::create_dir(path.join("sass"))?; }