Skip to content

Commit 90204c5

Browse files
author
pascalmh
committed
Initial release
0 parents  commit 90204c5

File tree

5 files changed

+167
-0
lines changed

5 files changed

+167
-0
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
## v0.0.1
4+
+ Initial release

git-commit-and-push-content.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
require(__DIR__ . DS . 'helpers.php');
3+
4+
/*
5+
* Pages
6+
*/
7+
kirby()->hook('panel.page.create', function ($page) {
8+
gitCommit('create(page): ' . $page->uri());
9+
});
10+
kirby()->hook('panel.page.update', function ($page) {
11+
gitCommit('update(page): ' . $page->uri());
12+
});
13+
kirby()->hook('panel.page.delete', function ($page) {
14+
gitCommit('delete(page): ' . $page->uri());
15+
});
16+
kirby()->hook('panel.page.sort', function ($page) {
17+
gitCommit('sort(page): ' . $page->uri());
18+
});
19+
kirby()->hook('panel.page.hide', function ($page) {
20+
gitCommit('hide(page): ' . $page->uri());
21+
});
22+
kirby()->hook('panel.page.move', function ($page) {
23+
gitCommit('move(page): ' . $page->uri());
24+
});
25+
26+
/*
27+
* File
28+
*/
29+
kirby()->hook('panel.file.move', function ($file) {
30+
gitCommit('move(file): ' . $file->page()->uri() . '/' . $file->filename());
31+
});
32+
kirby()->hook('panel.file.upload', function ($file) {
33+
gitCommit('upload(file): ' . $file->page()->uri() . '/' . $file->filename());
34+
});
35+
kirby()->hook('panel.file.replace', function ($file) {
36+
gitCommit('replace(file): ' . $file->page()->uri() . '/' . $file->filename());
37+
});
38+
kirby()->hook('panel.file.rename', function ($file) {
39+
gitCommit('rename(file): ' . $file->page()->uri() . '/' . $file->filename());
40+
});
41+
kirby()->hook('panel.file.update', function ($file) {
42+
gitCommit('update(file): ' . $file->page()->uri() . '/' . $file->filename());
43+
});
44+
kirby()->hook('panel.file.sort', function ($file) {
45+
gitCommit('sort(file): ' . $file->page()->uri() . '/' . $file->filename());
46+
});
47+
kirby()->hook('panel.file.delete', function ($file) {
48+
gitCommit('delete(file): ' . $file->page()->uri() . '/' . $file->filename());
49+
});
50+
51+
/*
52+
* User
53+
*/
54+
kirby()->hook('panel.user.create', function ($user) {
55+
gitCommit('create(user): ' . $user->username());
56+
});
57+
kirby()->hook('panel.user.update', function ($user) {
58+
gitCommit('update(user): ' . $user->username());
59+
});
60+
kirby()->hook('panel.user.delete', function ($user) {
61+
gitCommit('delete(user): ' . $user->username());
62+
});
63+
64+
/*
65+
* Avatar
66+
*/
67+
kirby()->hook('panel.avatar.upload', function ($avatar) {
68+
gitCommit('upload(avatar): ' . $avatar->filename());
69+
});
70+
kirby()->hook('panel.avatar.delete', function ($avatar) {
71+
gitCommit('delete(avatar): ' . $avatar->filename());
72+
});

helpers.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Compose Commit message, appends " by Username"
4+
*
5+
* @param string $commitMessage
6+
* @return false
7+
*/
8+
function gitCommit($commitMessage) {
9+
exec(
10+
'cd ../content/ && ' .
11+
'git add -A &&' .
12+
'git commit -m "' . $commitMessage . ' by ' . site()->user() . '"' .
13+
(
14+
server::get('SERVER_ADDR') != "localhost"
15+
? ' && git push "ext::ssh -i ' .
16+
c::get('gcapcSshKeyPath') . ' ' .
17+
c::get('gcapcGitServer') . ' %S ' .
18+
c::get('gcapcGitRepository') . '"'
19+
: ''
20+
),
21+
$output
22+
);
23+
24+
return false;
25+
}

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "git-commit-and-push-content",
3+
"readable": "Git Commit and Push Content",
4+
"version": "0.0.1",
5+
"stable": true,
6+
"description": "Version Controle your Content-Folder",
7+
"author": "Pascal Küsgen",
8+
"url": "http://pascalmh.de"
9+
}

readme.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Kirby - Git Commit And Push Content
2+
3+
This is a plugin for [Kirby](http://getkirby.com/) that Commits and Pushes Changes made via the Panel to your Git Repository.
4+
5+
## Installation
6+
7+
### Create a new git repository for your content
8+
9+
Create a new git repository where you push your content to, name it `your-project_content`.
10+
11+
### Download and configure the Plugin
12+
13+
Put all the files into your `site/plugins/git-commit-and-push-content/` folder. If the `git-commit-and-push-content/` plugin folder doesn't exist then create it.
14+
15+
Or: go into you `site/plugins/` folder and `git clone https://github.com/Pascalmh/kirby-git-commit-and-push-content git-commit-and-push-content`.
16+
17+
Add this to your `site/config/config.php` and adapt it to your needs:
18+
```php
19+
// Plugin: git-commit-push-content
20+
c::set('gcapcSshKeyPath', '.ssh/id_rsa'); // .ssh/id_rsa
21+
c::set('gcapcGitServer', '[email protected]'); // [email protected]
22+
c::set('gcapcGitRepository', 'your-project/your-project_content.git'); // your-project/your-project_content.git
23+
```
24+
25+
`gcapcSshKeyPath` - Create a new Git User with Push Permissions, generate an ssh-key for it and put it on the server
26+
`gcapcGitServer` - Hostname with optional user, for example `[email protected]`
27+
`gcapcGitRepository` - your git repository `your-project/your-project_content.git`
28+
29+
### Init the content repo and push it
30+
31+
Remove `content/` folder from your current git repository
32+
```
33+
git rm --cached -r content
34+
git add -A
35+
git commit -m "Move Content Folder to separate repository"
36+
```
37+
38+
Add `content/` folder to new git repository
39+
40+
```
41+
cd content
42+
git init
43+
git remote add origin https://github.com/your-project/your-project_content.git
44+
git add -A
45+
git commit -m "Initial Content Commit"
46+
git push origin master
47+
```
48+
49+
## Usage
50+
51+
Just keep using the Panel as you are used to and watch the commits appear in you git repository!
52+
53+
If you are on localhost you need to push your changes manually.
54+
55+
## Author
56+
57+
Pascal 'Pascalmh' Küsgen <http://pascalmh.de>

0 commit comments

Comments
 (0)