opengraph.pm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::opengraph;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. our $VERSION = '0.1.4';
  7. sub import {
  8. hook(type => "pagetemplate", id => "opengraph", call => \&opengraph_tags);
  9. }
  10. sub opengraph_tags {
  11. my %args = @_;
  12. ${args}{template}->param('OPENGRAPH' => 1);
  13. my ${title} = pagetitle(${args}{destpage});
  14. my ${url} = urlto(${args}{destpage}, 'index', '1');
  15. my ${image} = urlto('logo.png', 'index', '1');
  16. my ${type} = pagetype(${args}{destpage});
  17. my ${opengraph_title} = ${title} || ${config}{'opengraph_title'} || "ikiwiki";
  18. my ${opengraph_description} = ${config}{'opengraph_description'} || "ikiwiki";
  19. my ${opengraph_type} = ${type} || ${config}{'opengraph_type'} || "website";
  20. my ${opengraph_image} = ${image} || ${config}{'opengraph_image'} || "http://ikiwiki.info/logo/ikiwiki.png";
  21. my ${opengraph_url} = ${url} || ${config}{'opengraph_url'} || "http://ikiwiki.info/";
  22. my ${opengraph_tags} =<<EOF;
  23. <meta property="og:title" content="${opengraph_title}">
  24. \t<meta property="og:description" content="${opengraph_description}"/>
  25. \t<meta property="og:type" content="${opengraph_type}">
  26. \t<meta property="og:image" content="${opengraph_image}">
  27. \t<meta property="og:url" content="${opengraph_url}">
  28. EOF
  29. ${args}{template}->param('OPENGRAPH_TAGS' => ${opengraph_tags})
  30. }
  31. 1;
  32. __END__
  33. =head1 NAME
  34. IkiWiki::Plugin::opengraph - Adds Open Graph tags on the html head
  35. =head1 DESCRIPTION
  36. This plugin implements the Open Graph tags in the head of the hmtl for all
  37. pages, provided you configure it properly and add it to the current
  38. template. For more information on what is Open Graph, visit
  39. <https://en.wikipedia.org/wiki/Open_Graph>. To test your site against the
  40. Open Graph rules, use the tool available on
  41. <https://developers.facebook.com/tools/debug/og/object/>.
  42. WARNING: Open Graph is modern spyware. You should use this if and only if
  43. you don't mind making the readers of your wiki/blog being tracked by evil
  44. corporations without their consent. By using this plugin you are being mean
  45. to the people who are reading your content. You have been warned.
  46. =head1 INSTALLATION
  47. Put F<opengraph.pm> in F<$HOME/.ikiwiki/IkiWiki/Plugin/> or elsewhere in
  48. your C<@INC> path. Or read <http://ikiwiki.info/plugins/install/>.
  49. =head1 CONFIGURATION
  50. Add to the configuration in your F<blog.setup> file.
  51. ## Open Graph plugin
  52. # For more information, see
  53. # <https://en.wikipedia.org/wiki/Open_Graph#Open_Graph_protocol>.
  54. # Default values for <http://ikiwiki.info>
  55. # obtained from <https://developers.facebook.com/tools/debug/og/object/>
  56. # meta property="og:title"
  57. opengraph_title: "ikiwiki"
  58. # meta property="og:type"
  59. opengraph_type: "website"
  60. # meta property="og:url"
  61. opengraph_url: "http://ikiwiki.info/"
  62. # meta property="og:image"
  63. opengraph_image: "http://ikiwiki.info/logo/ikiwiki.png"
  64. # meta property="og:description"
  65. opengraph_description: "Ikiwiki is a wiki compiler."
  66. Add C<opengraph> to the list of plugins:
  67. add_plugins => [qw{goodstuff opengraph}],
  68. =head1 TEMPLATES
  69. You will need to add the following code to F<page.tmpl> on the current
  70. template. It **must** be in the <head> section of the <html>. I recommend
  71. puting it after the <title> tag.
  72. <TMPL_IF OPENGRAPH>
  73. <TMPL_VAR OPENGRAPH_TAGS>
  74. </TMPL_IF>
  75. =head1 BUGS AND LIMITATIONS
  76. ...that's not a bug. It's an issue. Issues shall be reported at
  77. https://notabug.org/hiatobr/ikiwiki-plugin-opengraph/issues
  78. Seriously, I don't know how to fetch the current page's description. Help on
  79. that is appreciated.
  80. =head1 LICENSE AND COPYRIGHT
  81. Copyleft (.) 2015 Hacklab Independência
  82. This program is free software: you can redistribute it and/or modify
  83. it under the terms of the GNU General Public License as published by
  84. the Free Software Foundation, either version 3 of the License, or
  85. (at your option) any later version.
  86. This program is distributed in the hope that it will be useful,
  87. but WITHOUT ANY WARRANTY; without even the implied warranty of
  88. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  89. GNU General Public License for more details.
  90. You should have received a copy of the GNU General Public License
  91. along with this program. If not, see <http://www.gnu.org/licenses/>.
  92. =head1 SEE ALSO
  93. =over 4
  94. =item https://ikiwiki.info/plugins/contrib/opengraph/
  95. =item https://en.wikipedia.org/wiki/Open_Graph
  96. =back