Package: lektor-git-src-publisher
lektor-git-src-publisherLektor's wonderful interface enables non-technical users to modify
the source of a Lektor-based site and publish the resulting website.However, if such source code is managed with git, the user will still have to
fiddle around with git clients or interfaces in order collaborate with others.This simple plugin enables two publish targets, one to update the page's
source code from a remote, and one to update the remote with the local
changes.Using thisStepsSetup theREMOTEand its authentication (out of scope for this plugin)Installlektor-git-src-publisherAdd the publishers to the projectlektor serveand profit!DetailsIn order to install the plugin you can add following to your.lektorprojectfile:[packages]
lektor-git-src-publisher = 0.2.2Or follow theofficial plugin instructions.In order to enable the publishers, you also modify your.lektorprojectfile:[servers.update]
name = Update from Remote
enabled = yes
target = gitsrc-forcepull://main

[servers.push]
name = Push to Remote
enabled = yes
target = gitsrc-push://mainNotice that this plugin registers thegitsrc-forcepull://BRANCHandgitsrc-push://BRANCHschemas.It is conceivable to have multiple publishers, e.g. one for astagingand
one for amainbranch. See thelimitations.Trying it outWhen running on a POSIX environment, you can:cd test_projects
# This generates the sample projects and initialises bare git repositories
# to facilitate testing.
./gen_projects.shThen run one of the test projects as follows:# Most standard setup
lektor --project minimal serve
# An example with the .lektorproject not running at the root of the repo
lektor --project nested/project/minimal serveWhen using the special publisher, the bare repositories created intest_projects/minimal.gitandtest_projects/nested.gitrespectively will
be updated with your changes.Getting in touch / collaboratingIf you just want to say hi/thanks or ask something, we are onMatrix!
Get in touch with us at#oss:camilion.euor through
our website:https://camilion.eu.If you have an issue with this pluginopen an Issue.If you have an improvement you'd like to have shipped with this plugin,
either get in touch with us, or open an Issue or a Pull Request.We mirror the code to GitHub from our infra, so PRs from any other code
hosting platforms are very welcome as well.A special mention goes to our friends atungleich, who
also needed this and provided the feedback and motivation needed to push
this forward.LimitationsDue to the way this is done, the Lektor server can be confused if you change
the.lektorprojecttoo much under its feet, simple things should be alright
and, when in doubt, restart the Lektor server after making big changes.Gory detailsThis plugin uses Lektor'spublisher APIin a
non-traditional fashion, instead of publishing the resulting artifacts:gitsrc-forcepull: updates the source working directory to pull remote
changes.gitsrc-push: auto-commits and pushes to the configured remote.Thesource codeis quite straight forward, when in doubt do read it!gitsrc-forcepullThis is roughly equivalent to following pseudo-code:# Save local changes
git stash
# Update remotes
git fetch --progress
if (BRANCH != CURRENT_BRANCH) {
    # Ensure we are working on the specified branch
    git checkout -b BRANCH -t REMOTE/BRANCH
}
# Merge changes as necessary
git merge --strategy=recursive --strategy-option=theirs
# Restore local changes
git stash popThis needs more testing, but appears to be robust enough for simple use-cases
and should certainly be enough if the user updates before making changes.gitsrc-pushThis is roughly equivalent to following pseudo-code:# Stage local changes
git add .
# Commit staged changes
git commit -m "Updated from Lektor"
# Push
git push REMOTE BRANCHYou may want to setup theGIT_COMMITTER_NAMEandGIT_COMMITTER_EMAILenvironment variables before running Lektor.