Skip to content

Commit 6f5c1b5

Browse files
committed
fix(deploy): preserve content.md changes in personal mode during deployment
- Add content_md field to SiteBuilder to hold pre-loaded content - Create new_with_config_and_content() method for deployment scenarios - Read content.md before git stashing to preserve uncommitted changes - Update generate_personal_index() to use pre-loaded content when available - Bump version to 0.4.1 Fixes issue where blogr deploy would not include uncommitted changes to content.md for personal mode sites, as the file was being stashed before the build process.
1 parent d33e3c1 commit 6f5c1b5

File tree

6 files changed

+58
-11
lines changed

6 files changed

+58
-11
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ thiserror = "2.0"
1010
walkdir = "2.3"
1111

1212
[workspace.package]
13-
version = "0.4.0"
13+
version = "0.4.1"
1414
edition = "2021"
1515
authors = ["bahdotsh"]
1616
license = "MIT"

blogr-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ name = "blogr"
1212
path = "src/main.rs"
1313

1414
[dependencies]
15-
blogr-themes = { version = "0.4.0", path = "../blogr-themes" }
15+
blogr-themes = { version = "0.4.1", path = "../blogr-themes" }
1616
clap = { version = "4.0", features = ["derive"] }
1717
ratatui = "0.24"
1818
crossterm = "0.27"

blogr-cli/src/commands/deploy.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ pub async fn handle_deploy(branch: String, message: Option<String>) -> Result<()
3636
let github_config = config.github.as_ref()
3737
.ok_or_else(|| anyhow!("GitHub configuration not found. Initialize with GitHub integration or configure manually."))?;
3838

39+
// For personal mode, read content.md BEFORE stashing to preserve uncommitted changes
40+
let content_md = if config.site.site_type == "personal" {
41+
let content_md_path = project.root.join("content.md");
42+
if content_md_path.exists() {
43+
Some(
44+
fs::read_to_string(&content_md_path)
45+
.with_context(|| "Failed to read content.md")?,
46+
)
47+
} else {
48+
None
49+
}
50+
} else {
51+
None
52+
};
53+
3954
Console::step(2, 7, "Preparing git repository...");
4055

4156
// Open the git repository
@@ -78,10 +93,11 @@ pub async fn handle_deploy(branch: String, message: Option<String>) -> Result<()
7893
// Build the site AFTER handling git state to ensure build directory exists
7994
// Use a temporary directory outside the project to avoid conflicts
8095
let temp_output = std::env::temp_dir().join(format!("blogr-deploy-{}", Uuid::new_v4()));
81-
// Use the pre-loaded config to avoid issues with git stashing
82-
let site_builder = SiteBuilder::new_with_config(
96+
// Use the pre-loaded config and content.md to avoid issues with git stashing
97+
let site_builder = SiteBuilder::new_with_config_and_content(
8398
project.clone(),
8499
config.clone(),
100+
content_md,
85101
Some(temp_output.clone()),
86102
false,
87103
false,

blogr-cli/src/generator/site.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub struct SiteBuilder {
3131
include_drafts: bool,
3232
/// Include future posts in build
3333
include_future: bool,
34+
/// Pre-loaded content.md (used during deploy to preserve uncommitted changes)
35+
content_md: Option<String>,
3436
}
3537

3638
impl SiteBuilder {
@@ -211,9 +213,26 @@ Thank you!`);
211213
output_dir,
212214
include_drafts,
213215
include_future,
216+
content_md: None,
214217
})
215218
}
216219

220+
/// Create a new site builder with pre-loaded config and content.md
221+
/// Used during deployment to preserve uncommitted changes
222+
pub fn new_with_config_and_content(
223+
project: Project,
224+
config: Config,
225+
content_md: Option<String>,
226+
output_dir: Option<PathBuf>,
227+
include_drafts: bool,
228+
include_future: bool,
229+
) -> Result<Self> {
230+
let mut builder =
231+
Self::new_with_config(project, config, output_dir, include_drafts, include_future)?;
232+
builder.content_md = content_md;
233+
Ok(builder)
234+
}
235+
217236
/// Build the entire site
218237
pub fn build(&self) -> Result<()> {
219238
println!("🚀 Building site with theme '{}'", self.config.theme.name);
@@ -370,11 +389,23 @@ Thank you!`);
370389
context.insert("current_year", &Utc::now().year());
371390

372391
// Read and parse content.md for sections data
373-
let content_md_path = self.project.root.join("content.md");
374-
if content_md_path.exists() {
375-
let content_md = fs::read_to_string(&content_md_path)
376-
.map_err(|e| anyhow!("Failed to read content.md: {}", e))?;
392+
// Use pre-loaded content if available (for deployment with uncommitted changes),
393+
// otherwise read from disk
394+
let content_md = if let Some(preloaded) = &self.content_md {
395+
Some(preloaded.clone())
396+
} else {
397+
let content_md_path = self.project.root.join("content.md");
398+
if content_md_path.exists() {
399+
Some(
400+
fs::read_to_string(&content_md_path)
401+
.map_err(|e| anyhow!("Failed to read content.md: {}", e))?,
402+
)
403+
} else {
404+
None
405+
}
406+
};
377407

408+
if let Some(content_md) = content_md {
378409
// Parse frontmatter to get sections
379410
if let Ok((frontmatter, _)) = self.parse_frontmatter(&content_md) {
380411
if let Ok(frontmatter_data) =

blogr-themes/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "blogr-themes"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
edition.workspace = true
55
authors.workspace = true
66
license.workspace = true

0 commit comments

Comments
 (0)