-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat:] Add Watch Feature to Monitor Input Folder for Changes #60
Conversation
Signed-off-by: Akash <[email protected]>
That's great @SkySingh04 There was a major refactor on the weekend, so now the code is better separated in modules. The bad part is that you gonna need to rebase / resolve conflicts. The good part is that you can now rely on |
Signed-off-by: Akash <[email protected]>
It looks like some tipe of Locking mechanism will be required [2024-10-23T10:02:30Z INFO marmite::site] Site generated at: /tmp/site/
[2024-10-23T10:02:30Z INFO marmite::site] Watching for changes in folder: example
[2024-10-23T10:02:35Z INFO marmite::site] Change detected. Rebuilding site...
[2024-10-23T10:02:35Z ERROR marmite::site] Error: Duplicate slug found: 'what-is-marmite-static-site-generator' - try setting any of `title`, `slug` as a unique text, or leave both empty so filename will be assumed. The thread sleeps for one sec, and then another suddenly tries to rebuild using the shared I guess that, before rebuilding it is going to be needed to cleanup the Then apply some Mutex on the site_data Initially let site_data = Arc::new(Mutex::new(Data::new(config_str)));
let site_data_clone = Arc::clone(&site_data); Then on the closure let mut site_data = site_data.lock().unwrap(); // lock to prevent race condition.
site_data.posts = Vec::new();
site_data.pages = Vec::new();
collect_content(&content_dir, &mut site_data);
detect_slug_collision(&site_data);
// Sort posts by date (newest first)
site_data.posts.sort_by(|a, b| b.date.cmp(&a.date));
// Sort pages on title
site_data.pages.sort_by(|a, b| a.title.cmp(&b.title)); This change will probably spawn some adjusts on other places to get BTW: I added a justfile
|
@rochacbruno Your requested changes have been made |
@SkySingh04 that's great, I executed |
For the |
Sure @rochacbruno , I can raise a PR for that as well ✅ |
Description
This PR introduces the
--watch
flag to themarmite
project, allowing it to monitor theinput_folder
for any changes and rebuild the site when changes are detected. This feature was inspired by similar implementations in static site generators like Zola and Cobalt.Key features added:
--watch
flag enables the program to watch theinput_folder
and trigger site rebuilds upon file changes.--watch --serve
option allows simultaneous file watching and serving the site via an HTTP server.Changes
--watch
flag support to enable file system monitoring for changes.input_folder
in anArc
to share it across threads, ensuring thread safety.hotwatch
) that triggers site regeneration when changes are detected ininput_folder
.Known Issues:
Currently, there are still some lifetime errors due to Rust's ownership system, specifically around borrowing
input_folder
. The error:input_folder
is safely shared and accessible within the file-watching closure.Next Steps:
input_folder
within closures.--watch --serve
.Feel free to review the implementation so far, and I’ll continue working on the remaining issues!
Checklist:
--serve
.Related Issue : #34