Skip to content

Commit 21bc82d

Browse files
committed
Genesis
0 parents  commit 21bc82d

26 files changed

+2100
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
4+
## [1.0.0-alpha] - 2017-02-26
5+
### Initial release

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"chriskonnertz/open-graph": "^1.0"
4+
}
5+
}

composer.lock

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

open-graph.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
/**
4+
* Kirby Open Graph Plugin
5+
*
6+
* @version 1.0.0-alpha
7+
* @author Pedro Borges <[email protected]>
8+
* @copyright Pedro Borges <[email protected]>
9+
* @link https://github.com/pedroborges/kirby-autogit
10+
* @license MIT
11+
*/
12+
13+
// Load Composer dependencies
14+
require __DIR__ . DS . 'vendor' . DS . 'autoload.php';
15+
16+
function openGraph($page)
17+
{
18+
$og = new ChrisKonnertz\OpenGraph\OpenGraph(true);
19+
$og->template("<meta property=\"{{name}}\" content=\"{{value}}\">\n");
20+
21+
if (c::get('open-graph.validate', true) && c::get('debug', false)) {
22+
$og->validate();
23+
}
24+
25+
$attributes = null;
26+
$pageTemplate = $page->intendedTemplate();
27+
$templates = c::get('open-graph.templates', []);
28+
$properties = c::get('open-graph.default', [
29+
'title' => $page->title(),
30+
'url' => $page->url(),
31+
'site_name' => site()->title(),
32+
'type' => 'website'
33+
]);
34+
35+
if (isset($templates[$pageTemplate])) {
36+
$properties = array_merge($properties, $templates[$pageTemplate]);
37+
}
38+
39+
foreach($properties as $tag => $value) {
40+
if (is_int($tag)) {
41+
$tag = $value;
42+
$value = null;
43+
}
44+
45+
if ($tag === 'attributes' && is_callable($value)) {
46+
$attributes = $value($page);
47+
} elseif (is_callable($value)) {
48+
$value = $value($page);
49+
} elseif (is_null($value)) {
50+
$value = $page->$tag();
51+
} elseif ($value instanceof Field && $value->isEmpty()) {
52+
$value = null;
53+
}
54+
55+
if (! is_null($attributes) && isset($properties['type'])) {
56+
$type = $properties['type'];
57+
$og->attributes($type, $attributes);
58+
} elseif ($tag === 'locale:alternate' && is_array($value)) {
59+
foreach ($value as $locale) {
60+
$og->tag($tag, $locale);
61+
}
62+
} elseif (! empty($value)) {
63+
$og->tag($tag, $value);
64+
}
65+
}
66+
67+
if (count($og->tags()) > 0) {
68+
return $og->renderTags();
69+
}
70+
}
71+
72+
kirby()->set('page::method', 'openGraph', function($page) {
73+
return openGraph($page);
74+
});

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "open-graph",
3+
"author": "Pedro Borges <[email protected]>",
4+
"version": "1.0.0-alpha",
5+
"description": "Kirby Open Graph",
6+
"type": "kirby-plugin",
7+
"license": "MIT"
8+
}

readme.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Kirby Open Graph (WIP) [![Release](https://img.shields.io/github/release/pedroborges/kirby-open-graph.svg)](https://github.com/pedroborges/kirby-open-graph/releases) [![Issues](https://img.shields.io/github/issues/pedroborges/kirby-open-graph.svg)](https://github.com/pedroborges/kirby-open-graph/issues)
2+
3+
A Kirby CMS plugin that builds [Open Graph](http://ogp.me) meta tags for your site.
4+
5+
## Requirements
6+
- Kirby 2.3.2+
7+
- PHP 5.4+
8+
9+
## Installation
10+
11+
### Download
12+
[Download the files](https://github.com/pedroborges/kirby-open-graph/archive/master.zip) and place them inside `site/plugins/open-graph`.
13+
14+
### Kirby CLI
15+
Kirby's [command line interface](https://github.com/getkirby/cli) is the easiest way to install the Open Graph plugin:
16+
17+
$ kirby plugin:install pedroborges/kirby-open-graph
18+
19+
To update it simply run:
20+
21+
$ kirby plugin:update pedroborges/kirby-open-graph
22+
23+
### Git Submodule
24+
You can add the Open Graph as a Git submodule.
25+
26+
<details>
27+
<summary><strong>Show Git Submodule instructions</strong> 👁</summary><p>
28+
29+
$ cd your/project/root
30+
$ git submodule add https://github.com/pedroborges/kirby-open-graph.git site/plugins/open-graph
31+
$ git submodule update --init --recursive
32+
$ git commit -am "Add Open Graph Git"
33+
34+
Updating is as easy as running a few commands.
35+
36+
$ cd your/project/root
37+
$ git submodule foreach git checkout master
38+
$ git submodule foreach git pull
39+
$ git commit -am "Update submodules"
40+
$ git submodule update --init --recursive
41+
42+
</p></details>
43+
44+
## Usage
45+
Once installed, you can use Open Graph in two ways:
46+
47+
### Page method
48+
<?php echo $page->openGraph() ?>
49+
50+
### Function
51+
<?php echo openGraph($page) ?>
52+
53+
Add your preferred method in the `head` of your HTML page and you are done! Well... not so fast. You will probably want to tweak the default meta tags or add new ones, so head over to the next section.
54+
55+
## Options
56+
The Open Graph plugin allows you to use a default set of meta tags via the `open-graph.default` option as well as use template specific sets by using the `open-graph.templates` option. Check out some examples:
57+
58+
```php
59+
c::get('open-graph.default', [
60+
'title' => page()->title(),
61+
'url' => page()->url(),
62+
'site_name' => site()->title(),
63+
'type' => 'website'
64+
]);
65+
66+
c::set('open-graph.templates', [
67+
'article' => [
68+
'type' => 'article',
69+
'image' => page()->cover()->url(),
70+
'attributes' => function($page) {
71+
return [
72+
// if strftime, use $page->date('%F')
73+
'published_time' => $page->date('c'),
74+
'modified_time' => $page->modified('c'),
75+
];
76+
}
77+
],
78+
]);
79+
```
80+
81+
When the current page has a specific Open Graph template defined at `open-graph.templates`, it will be merged and will override the default properties so you don't need to repeat yourself!
82+
83+
For more information on all the available open graph objects, check out the [specification](http://ogp.me).
84+
85+
## Roadmap
86+
- [ ] Add image attributes (width, height, type)
87+
- [ ] Add author profile
88+
- [ ] Enable tags array
89+
90+
## Change Log
91+
All notable changes to this project will be documented at: <https://github.com/pedroborges/kirby-open-graph/blob/master/changelog.md>
92+
93+
## License
94+
Open Graph plugin is open-sourced software licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php).
95+
96+
Copyright © 2017 Pedro Borges <[email protected]>

vendor/autoload.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
require_once __DIR__ . '/composer/autoload_real.php';
6+
7+
return ComposerAutoloaderInitcf01207af6e29b7b2fa627a56709c040::getLoader();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
8+
before_script:
9+
- curl -s http://getcomposer.org/installer | php
10+
- php composer.phar install --dev
11+
12+
script: phpunit
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 mcamara
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)