Skip to content
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

Rebuild site on config changes #8

Open
mpvosseller opened this issue Aug 11, 2014 · 8 comments
Open

Rebuild site on config changes #8

mpvosseller opened this issue Aug 11, 2014 · 8 comments

Comments

@mpvosseller
Copy link

If I run jekyll serve --watch the site does not seem to rebuild when a configuration file (_config.yml) changes.

Ideally --watch could watch config files too.

@parkr
Copy link
Member

parkr commented Nov 27, 2014

This is a larger structural change... right now we keep track of the site object and its configuration options are meant to be immutable within one process.

@parkr
Copy link
Member

parkr commented Nov 27, 2014

I guess ideally jekyll serve --watch would just re-run jekyll build and prop up a server. It'd have to fail when source or dest are changed, but only for serve. For build, it could just call jekyll build repeatedly.

@parkr
Copy link
Member

parkr commented Nov 27, 2014

But again, it's still a pretty hefty structural change. Hm.

@maxenko
Copy link

maxenko commented Aug 21, 2018

Is there some tool somehwere to automate ^C -> restart jekyll when _config.yml changes?

This is such a pain to work with, considering so many commercial templates for jekyll use _config.yml for bulk of layout and content.

@DirtyF DirtyF changed the title have jekyll serve --watch rebuild site when config files change Rebuild site on config.yml changes Aug 22, 2018
@DirtyF DirtyF changed the title Rebuild site on config.yml changes Rebuild site on config changes Aug 22, 2018
@murarisumit
Copy link

murarisumit commented Jul 23, 2019

Not sure how much it helps but, was facing similar problem. I had all the data in _config.yaml file, moved it to data directory (https://jekyllrb.com/docs/datafiles/), now there was no need for it.
I think this could be one of reason why data-dir were added(not sure though)

@ccope
Copy link

ccope commented Sep 21, 2019

I've written a daemon with functionality like this before. It watched its own config files, and did sanity checking on the loaded config file before updating its running configuration. If dealing with source and destination changes is too difficult for now, I think a reasonable short term solution would be comparing the keys in the new file and exiting if those values have changed. Or for a very hacky quick fix, exiting if the file changes at all. Continuing to run violates the user's expectations that the changes they made have taken effect.

@SimonEast
Copy link

I'd also love this, as I also have Jekyll themes that have a lot of config in _config.yml. I've learnt to migrate it to a data file, but it's a hassle.

Surely the process could just restart itself when it detects a change to the config. Would that really need a lot of rearchitecting?

@HofiOne
Copy link

HofiOne commented Jan 23, 2024

Surely the process could just restart itself when it detects a change to the config. Would that really need a lot of rearchitecting?

I agree, it will not be a big effort to implement this way, but it will be a huge help (yes, not the best solution, indeed, but it would be useful if it had a separate option that would be turned off by default, it would be backward compatible too)

Anyway, I'm using this script to achieve the same, far from perfect, but it will do what it should.

#!/bin/bash

REF_FILE="./.reftime"
ALL_PARAMS=$@

start_process() {
    echo -e "\nStarting to serve...\n"

    reset_watcher

    rm -Rf _site

    bundle exec jekyll serve ${ALL_PARAMS} &
    PROC_PID=$!

    echo -e "\n\n\n"
}

stop_process() {
    echo -e "\nStopping to serve...\n"
    kill -SIGTERM ${PROC_PID}
    wait ${PROC_PID}  # Wait for the process to terminate
    rm -f "${REF_FILE}"
}

check_watched_file_changed() {
    RES="$(find "$1" -newer "${REF_FILE}")"
    if [ "${RES}x" == "x" ]; then
        return 1
    else
        return 0
    fi
}

reset_watcher() {
    touch "${REF_FILE}"
}

handle_file_changes() {
    # Space separated list of files to watch
    FILES_TO_WATCH=("./_config.yml")

      for FILE in "${FILES_TO_WATCH[@]}"; do
        if check_watched_file_changed "${FILE}" ; then
            echo -e "\nFile $file changed. Restarting to serve...\n"

            stop_process
            start_process

            reset_watcher
            break  # Break out of the loop after the first file change
        fi
    done
}

# Main loop
start_process

while true; do
    KEY=0
    # Check for keyboard input without blocking
    read -t 1 -n 1 KEY

    case ${KEY} in
        s)
            stop_process
            exit 0
            ;;
        r)
            stop_process
            start_process
            ;;
    esac

    handle_file_changes

    sleep 1
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants