|
| 1 | +# Kirby Open Graph (WIP) [](https://github.com/pedroborges/kirby-open-graph/releases) [](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]> |
0 commit comments