ReadMe.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. Show Source plugin
  2. ------------------
  3. The plugin allows you to place a link to the source text of your posts in the
  4. same way that `Sphinx`_ does. It works for both pages and articles.
  5. Plugin Activation
  6. ~~~~~~~~~~~~~~~~~
  7. To activate the plugin ensure that you have ``SHOW_SOURCE_ON_SIDEBAR = True`` or
  8. ``SHOW_SOURCE_IN_SECTION = True`` your settings file.
  9. Making Source Available for Posts
  10. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. In order to mark posts so that their source may be seen use the following
  12. metadata values (unless overridden)- for reStructuredText documents:
  13. .. code-block:: reStructuredText
  14. :show_source: True
  15. or, in Markdown syntax
  16. .. code-block:: Markdown
  17. Show_source: True
  18. The plugin will render your source document URL to a corresponding
  19. ``article.show_source_url`` (or ``page.show_source_url``) attribute which is
  20. then accessible in the site templates.
  21. Show Source in the Templates
  22. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. To get the show source links on the article or page you will have to modify your
  24. theme, either as a sidebar display or at the foot of an article.
  25. Article or Page Sidebar Display
  26. *******************************
  27. How to get the source link to appear in the sidebar using the
  28. `pelican-bootstrap3`_ theme:
  29. .. code-block:: HTML
  30. {% if SHOW_SOURCE_ON_SIDEBAR %}
  31. {% if (article and article.show_source_url) or (page and page.show_source_url) %}
  32. <li class="list-group-item"><h4><i class="fa fa-tags fa-file-text"></i><span class="icon-label">This Page</span></h4>
  33. <ul class="list-group">
  34. <li class="list-group-item">
  35. {% if article %}
  36. <a href="{{ SITEURL }}/{{ article.show_source_url }}">Show source</a>
  37. {% elif page %}
  38. <a href="{{ SITEURL }}/{{ page.show_source_url }}">Show source</a>
  39. {% endif %}
  40. </li>
  41. </ul>
  42. </li>
  43. {% endif %}
  44. {% endif %}
  45. Article Footer Display
  46. **********************
  47. Here's some code (yes, `pelican-bootstrap3`_ again) to enable a souce link at
  48. the bottom of an article:
  49. .. code-block:: HTML
  50. {% if SHOW_SOURCE_IN_SECTION %}
  51. {% if article and article.show_source_url %}
  52. <section class="well" id="show-source">
  53. <h4>This Page</h4>
  54. <ul>
  55. <a href="{{ SITEURL }}/{{ article.show_source_url }}">Show source</a>
  56. </ul>
  57. </section>
  58. {% endif %}
  59. {% endif %}
  60. Overriding Default Plugin Behaviour
  61. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62. The default behaviour of the plugin is that revealing source is enabled on a
  63. case by case basis. This can be changed by the use of
  64. :py:`SHOW_SOURCE_ALL_POSTS = True` in the settings file. This does mean that the
  65. plugin will publish all source documents no matter whether ``show_source`` is
  66. set in the metadata or not.
  67. Unless overridden, each document is saved as the article or page slug attribute
  68. with a ``.txt`` extension.
  69. So for example, if your configuration had ``ARTICLE_SAVE_AS`` configured like
  70. so:
  71. .. code-block:: python
  72. ARTICLE_SAVE_AS = 'posts/{date:%Y}/{date:%m}/{slug}/index.html'
  73. Your static HTML post and source text document will be like the following:
  74. .. code-block:: Text
  75. posts/2016/10/welcome-to-my article/index.html
  76. posts/2016/10/welcome-to-my article/welcome-to-my article.txt
  77. You can add the ``SHOW_SOURCE_FILENAME`` variable in your settings file to
  78. override the source file name, so you could set the following:
  79. .. code-block:: python
  80. SHOW_SOURCE_FILENAME = 'my_source_file.txt'
  81. So with the ``ARTICLE_SAVE_AS`` configured as above, the files would be saved
  82. thus:
  83. .. code-block:: Text
  84. posts/2016/10/welcome-to-my article/index.html
  85. posts/2016/10/welcome-to-my article/my_source_file.txt
  86. This is the same behaviour for pages also.
  87. .. _`Sphinx`: http://www.sphinx-doc.org/
  88. .. _`pelican-bootstrap3`: https://github.com/getpelican/pelican-themes/tree/master/pelican-bootstrap3