Skip to content

Commit

Permalink
Merge pull request #1214 from getnikola/copy-and-link-listing-sources
Browse files Browse the repository at this point in the history
Listings should copy "raw" files and link to them
  • Loading branch information
ralsina committed Apr 21, 2014
2 parents 055d497 + 482892e commit 8f305c5
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,7 @@ New in master
Features
--------

* Link listings raw sources if COPY_SOURCES is True (Issue #1214)
* Much more powerful ``nikola plugin`` command (Issue #1189)
* More powerful console mode allows access to all nikola commands (Issue #830)
* New ```ROBOTS_EXCLUSIONS``` option listing resources to exclude from sitemap
Expand Down
4 changes: 4 additions & 0 deletions nikola/data/themes/base-jinja/templates/listing.tmpl
Expand Up @@ -16,4 +16,8 @@
{% if code %}
{{ code }}
{% endif %}
{% if source_link %}
<p class="sourceline"><a href="{{ source_link }}" id="sourcelink">{{ messages("Source") }}</a></p>
{% endif %}
{% endblock %}

4 changes: 4 additions & 0 deletions nikola/data/themes/base/templates/listing.tmpl
Expand Up @@ -16,4 +16,8 @@ ${ui.bar(crumbs)}
% if code:
${code}
% endif
% if source_link:
<p class="sourceline"><a href="${source_link}" id="sourcelink">${messages("Source")}</a></p>
% endif
</%block>

8 changes: 8 additions & 0 deletions nikola/data/themes/bootstrap-jinja/templates/listing.tmpl
Expand Up @@ -18,3 +18,11 @@
{{ code }}
{% endif %}
{% endblock %}

{% block sourcelink %}
{% if source_link %}
<li>
<a href="{{ source_link }}" id="sourcelink">{{ messages("Source") }}</a>
</li>
{% endif %}
{% endblock %}
8 changes: 8 additions & 0 deletions nikola/data/themes/bootstrap/templates/listing.tmpl
Expand Up @@ -18,3 +18,11 @@ ${ui.bar(crumbs)}
${code}
% endif
</%block>

<%block name="sourcelink">
% if source_link:
<li>
<a href="${source_link}" id="sourcelink">${messages("Source")}</a>
</li>
% endif
</%block>
8 changes: 8 additions & 0 deletions nikola/data/themes/bootstrap3-jinja/templates/listing.tmpl
Expand Up @@ -18,3 +18,11 @@
{{ code }}
{% endif %}
{% endblock %}

{% block sourcelink %}
{% if source_link %}
<li>
<a href="{{ source_link }}" id="sourcelink">{{ messages("Source") }}</a>
</li>
{% endif %}
{% endblock %}
8 changes: 8 additions & 0 deletions nikola/data/themes/bootstrap3/templates/listing.tmpl
Expand Up @@ -18,3 +18,11 @@ ${ui.bar(crumbs)}
${code}
% endif
</%block>

<%block name="sourcelink">
% if source_link:
<li>
<a href="${source_link}" id="sourcelink">${messages("Source")}</a>
</li>
% endif
</%block>
18 changes: 18 additions & 0 deletions nikola/plugins/task/listings.py
Expand Up @@ -84,6 +84,10 @@ def render_listing(in_name, out_name, folders=[], files=[]):
os.path.join(
kw['output_folder'],
kw['listings_folder'])))
if self.site.config['COPY_SOURCES']:
source_link = permalink[:-5]
else:
source_link = None
context = {
'code': code,
'title': title,
Expand All @@ -93,6 +97,7 @@ def render_listing(in_name, out_name, folders=[], files=[]):
'folders': natsort.natsorted(folders),
'files': natsort.natsorted(files),
'description': title,
'source_link': source_link,
}
self.site.render_template('listing.tmpl', out_name,
context)
Expand Down Expand Up @@ -148,6 +153,19 @@ def render_listing(in_name, out_name, folders=[], files=[]):
'uptodate': [utils.config_changed(uptodate)],
'clean': True,
}
if self.site.config['COPY_SOURCES']:
out_name = os.path.join(
kw['output_folder'],
root,
f)
yield {
'basename': self.name,
'name': out_name,
'file_dep': [in_name],
'targets': [out_name],
'actions': [(utils.copy_file, [in_name, out_name])],
'clean': True,
}

def listing_path(self, name, lang):
if not name.endswith('.html'):
Expand Down

0 comments on commit 8f305c5

Please sign in to comment.