remove unused plugins, fix missing links resume

This commit is contained in:
Vicky Steeves 2019-07-28 10:13:11 -04:00
parent 57ba378fa8
commit 718674b0f3
11 changed files with 6 additions and 744 deletions

View File

@ -41,17 +41,17 @@
<!- -----------------BEGIN EDUCATION--------------------- -->
<div class="tab-pane fade" id="edu">
<h3 class="mt-3">New York University <small class="text-muted">New York, NY, USA</small></h3>
<h4 style="text-decoration: underline;">Master of Computer Science <small class="text-muted">Expected 2022</small></h4>
<h4>Master of Computer Science <small class="text-muted">Expected 2022</small></h4>
<h3 class="mt-3">Simmons College <small class="text-muted">Boston, MA, USA</small></h3>
<h4 style="text-decoration: underline;">Master of Library and Information Science <small class="text-muted">August 2014</small></h4>
<h4>Master of Library and Information Science <small class="text-muted">August 2014</small></h4>
<h5>GPA: <small class="text-muted">3.85</small></h5>
<h5>Research Opportunities</h5>
<p><a href="http://gslis.simmons.edu/smallworld/smallworldProjectStaff.html">Small World Project.</a> Research done accompanying Dr. Kathy Wisser, March-June 2014. I provided software analysis using Gephi, a data visualization software, on researchers' social network analysis of historical relationships between literary figures.</p>
<h4 style="text-decoration: underline;">Bachelor of Science in Computer Science and Information Technology <small class="text-muted">May 2013</small></h4>
<h4>Bachelor of Science in Computer Science and Information Technology <small class="text-muted">May 2013</small></h4>
<h5>GPA: <small class="text-muted">3.75</small></h5>
<h5>Honours Thesis: <small class="text-muted">Computational Linguistic Approach to Inflection in Human Speech and Difference in Meaning</small></h5>
@ -222,12 +222,12 @@
<!- -----------------BEGIN PRESENTATIONS--------------------- -->
<div class="tab-pane fade" id="pre">
<ul class="job mt-3">
<li><a href="#">Partners in Reproducibility: Working with Researchers and Data Producers to Enhance Sharing, Reproducibility, and Long-term Access to Research Data</a>. Muilenburg Jennifer & Steeves, Vicky & Zhao, Shirley & McDougall, Janet. (2019, May). IASSIST 2019.</li>
<li><a href="#">Reproducibility, Preservation, and Access to Research with ReproZip and ReproServer</a>. Steeves, Vicky & <a href="https://remirampin.com" >Rampin, R.</a>. (2019, May). IASSIST 2019.</li>
<li>Panel - Partners in Reproducibility: Working with Researchers and Data Producers to Enhance Sharing, Reproducibility, and Long-term Access to Researosfch Data. Muilenburg Jennifer & Steeves, Vicky & Zhao, Shirley & McDougall, Janet. (2019, May). IASSIST 2019.</li>
<li><a href="https://osf.io/4uc3p/">Reproducibility, Preservation, and Access to Research with ReproZip and ReproServer</a>. Steeves, Vicky & <a href="https://remirampin.com" >Rampin, R.</a>. (2019, May). IASSIST 2019.</li>
<li><a href="http://doi.org/10.5281/zenodo.2673016">Qualitative Research Using Open Tools</a>. Duckles, Beth M. & Steeves, Vicky. (2019, May). csv,conf,v4.</li>
<li><a href="http://doi.org/10.5281/zenodo.2692864">The Role of Libraries in the Age of Computational Reproducibility</a>. Steeves, Vicky, & Hayden, Gabriele. (2019, May). csv,conf,v4.</li>
<li><a href="https://osf.io/sp2dx">Taguette: Open Qualitative Research</a>. Steeves, Vicky & DeMott, Sarah. (2019, February). Workshop for Seton Hall University.</li>
<li><a href="#">Advocating for Open: Putting Ethics Into Practice</a>. Marshall, Brianna & Steeves, Vicky & Vandegift, Micah. (2019, April). ACRL 2019. Cleveland, OH.</li>
<li><a href="https://osf.io/preprints/lissa/jhvtc/">Advocating for Open: Putting Ethics Into Practice</a>. Marshall, Brianna & Steeves, Vicky & Vandegift, Micah. (2019, April). ACRL 2019. Cleveland, OH.</li>
<li><a href="http://doi.org/10.5281/zenodo.1915952">Reproducibility Librarianship in Practice</a>. Steeves, Vicky. (2018, December). Webinar for LIBER.</li>
<li><a href="https://osf.io/xafsg/">ReproServer: Making Reproducibility Easier and Less Intrusive</a>. Steeves, V. & <a href="https://remirampin.com" >Rampin, R.</a>, Chirigati, F. & Freire, J. October 2018. <a href="https://sites.google.com/msdse.org/msdse-summit-2018/home?authuser=0">Moore-Sloan Data Science Environment</a>. Park City, Utah.</li>
<li><a href="https://osf.io/6hvpt">Best practices for reproducible research</a>. Steeves, V. October 2018. Harvard-Smithsonian Center for Astrophysics. Cambride, Massachusetts.</li>

View File

@ -1 +0,0 @@
# Plugin modules go here.

View File

@ -1,112 +0,0 @@
# Publication List
A Nikola plugin to easily manage publication list.
This plugin provides a directive `publication_list`, which reads a BibTeX file
and display the references in them on the web page.
The publications are displayed in the following way. All publications are sorted
by year in reverse order, i.e., recent publication first. Publications in the
same year are grouped together with a year subtitle. Within the same year,
publications are sorted by order they appear in the BibTeX file. Finally, each
publication is formatted with the designated style.
## Options
The `publication-list` directive accepts multiple options.
* `:bibtex_dir:` indicates the directory where the bibtex file of each
publication is generated. If empty, no bibtex file will be created for each
publication. The default is `bibtex`.
* `:detail_page_dir:` indicates the directory where the details pages of the
publications are stored. If empty, no details page will be created. The
default is `papers`.
* `:highlight_author:` indicates the author to highlight. Usually this is the
owner of the website. This can be a list of names separated by “;” if there are several
optional names.
In the BibTeX file entries, the following fields have special meanings.
* `abstract` is the abstract of the paper. If it is present, the abstract will
be available in the details page.
* `fulltext` is the URL to the full text of the paper (usually a PDF file). If
it is present, a "full text" link will be shown below the publication and the
PDF file will be embedded in the details page.
* Fields starting with `customlink` will add custom links below the publication.
For example, `customlinkslides` will add a link `[slides]` to the URL of the
value of the field.
If you need math support, please add the following to your `EXTRA_HEAD_DATA`
option in your `conf.py` file, then every math equation surrounded by `\(` and
`\)`, e.g., the ones in the abstracts and titles, will be rendered properly.
r'<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>'
## Example
A simple example:
Publications
------------
.. publication_list:: my-publications.bib
:style: unsrt
:highlight_author: Nikola Tesla
where `my-publications.bib` contains:
@article{a2015,
title = {One Article in 2015},
author = {Nikola Tesla},
year = 2015,
journal = {Great Journal},
volume = 1,
pages = {1--10},
fulltext = {/pdf/a2015.pdf}
}
@book{b2010,
title = {One Book in 2010},
author = {Isaac Newton and Nikola Tesla},
year = 2010,
isbn = {000-0000000000},
publisher = {Nikola Tesla Publishing Group},
fulltext = {http://example.org/b2010.pdf}
}
@inproceedings{p2015,
title = {One Conference in 2015},
booktitle = {Nikola Tesla Conference},
author = {Nikola Tesla},
year = 2015
}
If you have multiple bibtex files, you can specify them in one line, separated
by spaces. For example:
... publication_list:: my-novels.bib my-research-papers.bib my-collections.bib
Live examples:
- http://www.shudan.me/
- https://bishesh.github.io/publications/
## Customize Details Pages
You can also customize details pages. To do that, simply create files named
`publicationlist_label_after_abstract.html` or
`publicationlist_label_after_fulltext.html` in your template directory (usually
named `templates`). The contents in these files will be inserted into the
details page of the paper with that BibTeX label. For example, for a paper with
a BibTeX label `a2015`, you can create files
`publicationlist_a2015_after_abstract.html` and/or
`publicationlist_a2015_after_fulltext.html` to customize its details page.
## Screenshot
![publication-list screenshot](http://plugins.getnikola.com/__data__/publication-list-screenshot.png)
[list of styles]: https://bitbucket.org/pybtex-devs/pybtex/src/master/pybtex/style/formatting/
[Pybtex]: http://pybtex.org

View File

@ -1,14 +0,0 @@
[Core]
Name = publication_list
Module = publication_list
Tests = test_publication_list
[Nikola]
PluginCategory = CompilerExtension
Compiler = rest
[Documentation]
Author = Hong Xu
Version = 0.7.1
Website = https://www.topbug.net
Description = Easily manage publication list.

View File

@ -1,263 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright © 2016-2017 Hong Xu <hong@topbug.net>.
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the
# Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial portions of
# the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import os
import sys
from docutils import nodes
from docutils.parsers.rst import Directive, directives
from nikola.plugin_categories import RestExtension
from nikola.utils import get_logger, STDERR_HANDLER
from pybtex.database import BibliographyData, Entry
from pybtex.database.input.bibtex import Parser
from pybtex.markup import LaTeXParser
from pybtex.style.formatting.unsrt import Style as UnsrtStyle
from pybtex.style.template import href, tag
LOGGER = get_logger('scan_posts', STDERR_HANDLER)
class Style(UnsrtStyle):
"""The style for publication listing. It hyperlinks the title to the detail page if user sets it.
"""
def __init__(self, detail_page_url):
super().__init__()
self.detail_page_url = detail_page_url
def format_title(self, e, which_field, as_sentence=True):
"Override the UnsrtStyle format_title(), so we have the title hyperlinked."
title = tag('strong')[super().format_title(e, which_field, as_sentence)]
if self.detail_page_url:
url = '/'.join((self.detail_page_url, e.label + '.html'))
return href[url, title]
else:
return title
class Plugin(RestExtension):
name = "publication_list"
def set_site(self, site):
self.site = site
directives.register_directive('publication_list', PublicationList)
PublicationList.site = self.site
PublicationList.output_folder = self.site.config['OUTPUT_FOLDER']
return super(Plugin, self).set_site(site)
class PublicationList(Directive):
"""
Directive to list publications.
"""
has_content = False
required_arguments = 1
optional_arguments = sys.maxsize
option_spec = {
'bibtex_dir': directives.unchanged,
'detail_page_dir': directives.unchanged,
'highlight_author': directives.unchanged,
'style': directives.unchanged
}
def run(self):
bibtex_dir = self.options.get('bibtex_dir', 'bibtex')
detail_page_dir = self.options.get('detail_page_dir', 'papers')
highlight_authors = self.options.get('highlight_author', None)
if highlight_authors:
highlight_authors = highlight_authors.split(';')
style = Style(self.site.config['BASE_URL'] + detail_page_dir if detail_page_dir else None)
self.state.document.settings.record_dependencies.add(self.arguments[0])
all_entries = []
labels = set()
for a in self.arguments:
parser = Parser()
for item in parser.parse_file(a).entries.items():
if item[0] in labels: # duplicated entries
LOGGER.warning(
("publication_list: BibTeX entries with duplicated labels are found. "
"Only the first occurrence will be used."))
continue
labels.add(item[0])
all_entries.append(item)
# Sort the publication entries by year reversed
data = sorted(all_entries, key=lambda e: e[1].fields['year'], reverse=True)
html = '<div class="publication-list">\n'
cur_year = None
if bibtex_dir: # create the bibtex dir if the option is set
try:
os.makedirs(os.path.sep.join((self.output_folder, bibtex_dir)))
except OSError: # probably because the dir already exists
pass
if detail_page_dir: # create the detail page dir if the option is set
try:
os.makedirs(os.path.sep.join((self.output_folder, detail_page_dir)))
except OSError: # probably because the dir already exists
pass
for label, entry in data:
# print a year title when year changes
if entry.fields['year'] != cur_year:
if cur_year is not None: # not first year group
html += '</ul>'
cur_year = entry.fields['year']
html += '<h3>{}</h3>\n<ul>'.format(cur_year)
entry.label = label # Pass label to the style.
pub_html = list(style.format_entries((entry,)))[0].text.render_as('html')
if highlight_authors: # highlight one of several authors (usually oneself)
for highlight_author in highlight_authors:
# We need to replace all occurrence of space except for the last one with
# &nbsp;, since pybtex does it for all authors
count = highlight_author.count(' ') - 1
pub_html = pub_html.replace(
highlight_author.strip().replace(' ', '&nbsp;', count),
'<strong>{}</strong>'.format(highlight_author), 1)
html += '<li class="publication" style="padding-bottom: 1em;">' + pub_html
extra_links = ""
if 'fulltext' in entry.fields: # the link to the full text, usually a link to the pdf file
extra_links += '[<a href="{}">full text</a>] '.format(entry.fields['fulltext'])
bibtex_fields = dict(entry.fields)
# Collect and remove custom links (fields starting with "customlink")
custom_links = dict()
for key, value in bibtex_fields.items():
if key.startswith('customlink'):
custom_links[key[len('customlink'):]] = value
# custom fields (custom links)
for key, value in custom_links.items():
extra_links += '[<a href="{}">{}</a>] '.format(value, key)
# Remove some fields for the publicly available BibTeX file since they are mostly only
# used by this plugin.
for field_to_remove in ('abstract', 'fulltext'):
if field_to_remove in bibtex_fields:
del bibtex_fields[field_to_remove]
# Prepare for the bib file. Note detail_page_dir may need bib_data later.
bibtex_entry = Entry(entry.type, bibtex_fields, entry.persons)
bib_data = BibliographyData(dict({label: bibtex_entry}))
bib_string = bib_data.to_string('bibtex')
extra_links += '''
[<a href="javascript:void(0)" onclick="
(function(target, id) {{
if ($('#' + id).css('display') == 'block')
{{
$('#' + id).hide('fast');
$(target).text('BibTeX&#x25BC;')
}}
else
{{
$('#' + id).show('fast');
$(target).text('BibTeX&#x25B2;')
}}
}})(this, '{}');">BibTeX&#x25BC;</a>]
'''.format('bibtex-' + label)
if bibtex_dir: # write bib files to bibtex_dir for downloading
bib_link = '{}/{}.bib'.format(bibtex_dir, label)
bib_data.to_file('/'.join([self.output_folder, bib_link]), 'bibtex')
if extra_links or detail_page_dir or 'abstract' in entry.fields:
html += '<br>'
# Add the abstract link.
if 'abstract' in entry.fields:
html += '''
[<a href="javascript:void(0)" onclick="
(function(target, id) {{
if ($('#' + id).css('display') == 'block')
{{
$('#' + id).hide('fast');
$(target).text('abstract&#x25BC;')
}}
else
{{
$('#' + id).show('fast');
$(target).text('abstract&#x25B2;')
}}
}})(this, '{}');">abstract&#x25BC;</a>] '''.format('abstract-' + label)
display_none = '<div id="{}" style="display:none"><pre>{}</pre></div>'
bibtex_display = display_none.format(
'bibtex-' + label, bib_string)
abstract_text = str(
LaTeXParser(entry.fields['abstract']).parse()) if 'abstract' in entry.fields else ''
if detail_page_dir: # render the details page of a paper
page_url = '/'.join((detail_page_dir, label + '.html'))
html += '[<a href="{}">details</a>] '.format(
self.site.config['BASE_URL'] + page_url)
context = {
'title': str(LaTeXParser(entry.fields['title']).parse()),
'abstract': abstract_text,
'bibtex': bib_data.to_string('bibtex'),
'bibtex_link': '/' + bib_link if bibtex_dir else '',
'default_lang': self.site.config['DEFAULT_LANG'],
'label': label,
'lang': self.site.config['DEFAULT_LANG'],
'permalink': self.site.config['SITE_URL'] + page_url,
'reference': pub_html,
'extra_links': extra_links + bibtex_display
}
if 'fulltext' in entry.fields:
context['pdf'] = entry.fields['fulltext']
self.site.render_template(
'publication.tmpl',
os.path.sep.join((self.output_folder, detail_page_dir, label + '.html')),
context,
)
html += extra_links
# Add the hidden abstract and bibtex.
if 'abstract' in entry.fields:
html += '''
<div id="{}" class="publication-abstract" style="display:none">
<blockquote>{}</blockquote></div>
'''.format('abstract-' + label, abstract_text)
html += bibtex_display
html += '</li>'
if len(data) != 0: # publication list is nonempty
html += '</ul>'
html += '</div>'
return [nodes.raw('', html, format='html'), ]

View File

@ -1 +0,0 @@
pybtex>=0.21

View File

@ -1,65 +0,0 @@
{# -*- coding: utf-8 -*- #}
{% extends 'base.tmpl' %}
<%!
import os, mako
%>
{% macro include_if_exists(name) %}
<%
try:
tmpl = self.get_template(name)
except mako.exceptions.TemplateLookupException as e:
pass
else:
tmpl.render_context(context)
%>
{% endmacro %}
{% block extra_head %}
<style>
.publication-abstract {
text-align: justify;
hyphens: auto;
-webkit-hyphens: auto;
-moz-hyphens: auto;
-ms-hyphens:auto;
}
</style>
{% endblock %}
{% block content %}
<header class="page-header">
<h1>{{ title | h }}</h1>
</header>
<div class="reference">
<p>
{{ reference }}
{% if extra_links %}
<br/>{{ extra_links }}
{% endif %}
</p>
</div>
{% if abstract %}
<h2>Abstract</h2>
<div class="publication-abstract">
<p>{{ abstract | h }}</p>
</div>
{% endif %}
{{ include_if_exists("publicationlist_{ }_after_abstract.html".format(label))}}
{% if pdf %}
<h2>Full Text</h2>
<div>
<object data="{{ pdf }}" type="application/pdf" width="100%" style="height:90vh">
<p>Your browser does not support viewing the PDF file inline. Please click the link below to download the file.</p>
</object>
<p>[<a href="{{ pdf }}" download="{{ label }}.pdf">download</a>]</p>
</div>
{% endif %}
{{ include_if_exists("publicationlist_{ }_after_fulltext.html".format(label))}}
{% endblock %}

View File

@ -1,65 +0,0 @@
## -*- coding: utf-8 -*-
<%inherit file="base.tmpl"/>
<%!
import os, mako
%>
<%def name="include_if_exists(name)" buffered="True">
<%
try:
tmpl = self.get_template(name)
except mako.exceptions.TemplateLookupException as e:
pass
else:
tmpl.render_context(context)
%>
</%def>
<%block name="extra_head">
<style>
.publication-abstract {
text-align: justify;
hyphens: auto;
-webkit-hyphens: auto;
-moz-hyphens: auto;
-ms-hyphens:auto;
}
</style>
</%block>
<%block name="content">
<header class="page-header">
<h1>${title | h}</h1>
</header>
<div class="reference">
<p>
${reference}
% if extra_links:
<br/>${extra_links}
% endif
</p>
</div>
% if abstract:
<h2>Abstract</h2>
<div class="publication-abstract">
<p>${abstract | h}</p>
</div>
% endif
${include_if_exists("publicationlist_{}_after_abstract.html".format(label))}
% if pdf:
<h2>Full Text</h2>
<div>
<object data="${pdf}" type="application/pdf" width="100%" style="height:90vh">
<p>Your browser does not support viewing the PDF file inline. Please click the link below to download the file.</p>
</object>
<p>[<a href="${pdf}" download="${label}.pdf">download</a>]</p>
</div>
% endif
${include_if_exists("publicationlist_{}_after_fulltext.html".format(label))}
</%block>

View File

@ -1,17 +0,0 @@
Nikola Metadata Upgrade (v7 to v8)
==================================
This plugin fulfills two purposes:
1. It upgrades old-style tags metadata (`draft`, `private`, `mathjax`)
to new-style metadata, i.e. using the `status` and `has_math` metadata fields.
The tags were used in Nikola v7 and earlier, and are no longer used by default
in Nikola v8. If you are using them in your blog, **you will be warned** by
`nikola build` — otherwise, dont install this plugin (it wont do a thing
anyway and will only waste disk space and load time).
2. It converts sections to categories. If both section and category are specified
in a post, a warning is printed and the category kept.
The plugin adds the `nikola upgrade_metadata_v8` command. Remove the plugin
manually after the upgrade.

View File

@ -1,13 +0,0 @@
[Core]
Name = upgrade_metadata_v8
Module = upgrade_metadata_v8
[Nikola]
PluginCategory = Command
MinVersion = 8.0.0
[Documentation]
Author = Chris Warrick, Felix Fontein
Version = 0.1
website = https://getnikola.com/
Description = Convert special tags (draft, private, mathjax) to metadata

View File

@ -1,187 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright © 20142015, Chris Warrick.
# Copyright © 2018, Felix Fontein.
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the
# Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial portions of
# the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import unicode_literals
import io
import os
import sys
from nikola.plugin_categories import Command
from nikola import utils
class UpgradeMetadata(Command):
"""Convert special tags (draft, private, mathjax) to status and has_math metadata. Also removes sections."""
name = 'upgrade_metadata_v8'
doc_purpose = 'Convert special tags (draft, private, mathjax) to metadata'
cmd_options = [
{
'name': 'yes',
'short': 'y',
'long': 'yes',
'type': bool,
'default': False,
'help': 'Proceed without confirmation',
},
]
def _execute(self, options, args):
L = utils.get_logger('upgrade_metadata_v8', utils.STDERR_HANDLER)
if not self.site.config['USE_TAG_METADATA']:
L.error('This plugin can only be used if USE_TAG_METADATA is set to True.')
sys.exit(-1)
self.site.config['WARN_ABOUT_TAG_METADATA'] = False
# scan posts
self.site.scan_posts()
flagged = []
for post in self.site.timeline:
flag = False
if post.has_oldstyle_metadata_tags:
flag = True
for lang in self.site.config['TRANSLATIONS'].keys():
if 'section' in post.meta[lang]:
flag = True
if flag:
flagged.append(post)
if flagged:
if len(flagged) == 1:
L.info('1 post (and/or its translations) contains old-style metadata or has section metadata:')
else:
L.info('{0} posts (and/or their translations) contain old-style metadata or have section metadata:'.format(len(flagged)))
for post in flagged:
L.info(' ' + (post.metadata_path if post.is_two_file else post.source_path))
L.warn('Please make a backup before running this plugin. It might eat your data.')
if not options['yes']:
yesno = utils.ask_yesno("Proceed with metadata upgrade?")
if options['yes'] or yesno:
number_converted = 0
number_converted_partial = 0
for post in flagged:
converted = False
fully_converted = True
for lang in self.site.config['TRANSLATIONS'].keys():
# Get file names and extractor
extractor = post.used_extractor[lang]
is_two_file = post.is_two_file
if lang == post.default_lang:
fname = post.metadata_path if is_two_file else post.source_path
else:
meta_path = os.path.splitext(post.source_path)[0] + '.meta' if is_two_file else post.source_path
fname = utils.get_translation_candidate(post.config, meta_path, lang)
# We don't handle compilers which extract metadata for now
if post.compiler is extractor:
L.warn('Cannot convert {0} (language {1}), as metadata was extracted by compiler.'.format(fname, lang))
fully_converted = False
continue
# Read metadata and text from post file
if not os.path.exists(fname):
L.debug("File {0} does not exist, skipping.".format(fname))
continue
with io.open(fname, "r", encoding="utf-8-sig") as meta_file:
source_text = meta_file.read()
if not is_two_file:
_, content_str = extractor.split_metadata_from_text(source_text)
meta = extractor.extract_text(source_text)
# Consider metadata mappings
sources = {}
for m in ('tags', 'status', 'has_math', 'section', 'category'):
sources[m] = m
for foreign, ours in self.site.config.get('METADATA_MAPPING', {}).get(extractor.map_from, {}).items():
if ours in sources:
sources[ours] = foreign
for meta_key, hook in self.site.config.get('METADATA_VALUE_MAPPING', {}).get(extractor.map_from, {}).items():
if meta_key in sources.values():
L.warn('Cannot convert {0} (language {1}): a metadata value mapping is defined for "{2}"!'.format(fname, lang, meta_key))
# Update metadata
updated = False
tags = meta.get(sources['tags'], [])
tags_are_string = False
if not isinstance(tags, list):
tags_are_string = True
tags = [tag.strip() for tag in tags.split(',') if tag.strip()]
if 'draft' in [_.lower() for _ in tags]:
tags.remove('draft')
meta[sources['status']] = 'draft'
updated = True
if 'private' in tags:
tags.remove('private')
meta[sources['status']] = 'private'
updated = True
if 'mathjax' in tags:
tags.remove('mathjax')
meta[sources['has_math']] = 'yes'
updated = True
if meta.get(sources['section']):
if meta.get(sources['category']):
L.warn('Cannot completely {0} (language {1}): both section and category are specified. Please determine the correct category to use yourself!'.format(fname, lang))
fully_converted = False
else:
meta[sources['category']] = meta[sources['section']]
del meta[sources['section']]
updated = True
if tags_are_string:
meta[sources['tags']] = ', '.join(tags)
if not updated:
# Nothing to do (but successful)!
converted = True
continue
# Recombine metadata with post text if necessary, and write back to file
meta_str = utils.write_metadata(meta, metadata_format=extractor.name, compiler=post.compiler,
comment_wrap=(post.compiler.name != 'rest'), site=self.site)
final_str = meta_str if is_two_file else (meta_str + content_str)
with io.open(fname, "w", encoding="utf-8") as meta_file:
meta_file.write(final_str)
converted = True
if converted:
if fully_converted:
number_converted += 1
else:
number_converted_partial += 1
L.info('{0} out of {2} posts upgraded; {1} only converted partially '
'(see above output).'.format(number_converted + number_converted_partial, number_converted_partial, len(flagged)))
else:
L.info('Metadata not upgraded.')
else:
L.info('No posts found with special tags or section metadata. No action is required.')
L.info('You can safely set the USE_TAG_METADATA and the WARN_ABOUT_TAG_METADATA settings to False.')