[tor-commits] [community/staging] Remove unused macros

emmapeel at torproject.org emmapeel at torproject.org
Mon May 27 13:27:26 UTC 2019


commit 2f17000dc5b63f6fd7aafa92e2b2538dd7445fe2
Author: hiro <hiro at torproject.org>
Date:   Sat Apr 27 21:49:53 2019 +0200

    Remove unused macros
---
 packages/markdown-header-anchors/.gitignore        |  7 ++++
 packages/markdown-header-anchors/CHANGES.md        | 30 +++++++++++++
 packages/markdown-header-anchors/LICENSE           | 31 ++++++++++++++
 packages/markdown-header-anchors/MANIFEST.in       |  1 +
 packages/markdown-header-anchors/README.md         | 33 +++++++++++++++
 .../lektor_markdown_header_anchors.py              | 49 ++++++++++++++++++++++
 packages/markdown-header-anchors/setup.cfg         |  2 +
 packages/markdown-header-anchors/setup.py          | 40 ++++++++++++++++++
 templates/macros/contact.html                      |  3 --
 templates/macros/downloads.html                    | 48 ---------------------
 templates/macros/jobs.html                         | 15 -------
 templates/macros/people.html                       | 49 ----------------------
 templates/macros/press.html                        | 19 ---------
 templates/macros/reports.html                      | 21 ----------
 templates/macros/sponsors.html                     | 11 -----
 15 files changed, 193 insertions(+), 166 deletions(-)

diff --git a/packages/markdown-header-anchors/.gitignore b/packages/markdown-header-anchors/.gitignore
new file mode 100644
index 0000000..de9d237
--- /dev/null
+++ b/packages/markdown-header-anchors/.gitignore
@@ -0,0 +1,7 @@
+dist
+build
+*.egg-info
+*.pyc
+*.pyo
+*~
+*#
\ No newline at end of file
diff --git a/packages/markdown-header-anchors/CHANGES.md b/packages/markdown-header-anchors/CHANGES.md
new file mode 100644
index 0000000..2cfdadb
--- /dev/null
+++ b/packages/markdown-header-anchors/CHANGES.md
@@ -0,0 +1,30 @@
+Changelog
+=========
+
+These are all the changes in Lektor Markdown Header Anchors
+since the first public release.
+
+0.3.1
+
+Release date 25th of January, 2019
+
+- Release with py2 and py3 wheel.
+
+0.3
+
+Release date 12th of May, 2018
+
+- Setup updates.
+- Use random id as anchor
+
+0.2
+
+Release date 20th of January, 2017
+
+- Workaround for weird header setups
+
+0.1
+
+Release date 24th of December, 2015
+
+- Initial Release.
diff --git a/packages/markdown-header-anchors/LICENSE b/packages/markdown-header-anchors/LICENSE
new file mode 100644
index 0000000..0921373
--- /dev/null
+++ b/packages/markdown-header-anchors/LICENSE
@@ -0,0 +1,31 @@
+Copyright (c) 2015 by Armin Ronacher.
+
+Some rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+
+    * The names of the contributors may not be used to endorse or
+      promote products derived from this software without specific
+      prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/packages/markdown-header-anchors/MANIFEST.in b/packages/markdown-header-anchors/MANIFEST.in
new file mode 100644
index 0000000..64ad321
--- /dev/null
+++ b/packages/markdown-header-anchors/MANIFEST.in
@@ -0,0 +1 @@
+include README.md LICENSE
diff --git a/packages/markdown-header-anchors/README.md b/packages/markdown-header-anchors/README.md
new file mode 100644
index 0000000..6fcce47
--- /dev/null
+++ b/packages/markdown-header-anchors/README.md
@@ -0,0 +1,33 @@
+# lektor-markdown-header-anchors
+
+This plugin extends the markdown support in Lektor in a way that headlines
+are given anchors and a table of contents is collected.
+
+## Enabling the Plugin
+
+To enable the plugin run this command:
+
+```shell
+$ lektor plugins add markdown-header-anchors
+```
+
+## In Templates
+
+Within templates it becomes possible to access the `.toc` property of
+markdown data.  It's a list where each item has the following attributes:
+
+* `anchor`: the name of the anchor
+* `title`: the title of the headline as HTML
+* `children`: a list of headers below that header
+
+Example rendering:
+
+```jinja
+<h4>Table Of Contents</h4>
+<ul class="toc">
+{% for item in this.body.toc recursive %}
+  <li><a href="#{{ item.anchor }}">{{ item.title }}</a>{%
+   if item.children %}<ul>{{ loop(item.children) }}</ul>{% endif %}</li>
+{% endfor %}
+</ul>
+```
diff --git a/packages/markdown-header-anchors/lektor_markdown_header_anchors.py b/packages/markdown-header-anchors/lektor_markdown_header_anchors.py
new file mode 100644
index 0000000..1c324e5
--- /dev/null
+++ b/packages/markdown-header-anchors/lektor_markdown_header_anchors.py
@@ -0,0 +1,49 @@
+from lektor.pluginsystem import Plugin
+import uuid
+from lektor.utils import slugify
+from markupsafe import Markup
+from collections import namedtuple
+
+
+TocEntry = namedtuple('TocEntry', ['anchor', 'title', 'children'])
+
+
+class MarkdownHeaderAnchorsPlugin(Plugin):
+    name = 'Markdown Header Anchors'
+    description = u'Lektor plugin that adds anchors and table of contents to markdown headers.'
+
+    def on_markdown_config(self, config, **extra):
+        class HeaderAnchorMixin(object):
+            def header(renderer, text, level, raw):
+                if self.get_config().get('anchor-type') == "random":
+                    anchor = uuid.uuid4().hex[:6]
+                else:
+                    anchor = slugify(raw)
+                renderer.meta['toc'].append((level, anchor, Markup(text)))
+                return '<h%d id="%s">%s</h%d>' % (level, anchor, text, level)
+        config.renderer_mixins.append(HeaderAnchorMixin)
+
+    def on_markdown_meta_init(self, meta, **extra):
+        meta['toc'] = []
+
+    def on_markdown_meta_postprocess(self, meta, **extra):
+        prev_level = None
+        toc = []
+        stack = [toc]
+
+        for level, anchor, title in meta['toc']:
+            if prev_level is None:
+                prev_level = level
+            elif prev_level == level - 1:
+                stack.append(stack[-1][-1][2])
+                prev_level = level
+            elif prev_level > level:
+                while prev_level > level:
+                    # Just a simple workaround for when people do weird
+                    # shit with headlines.
+                    if len(stack) > 1:
+                        stack.pop()
+                    prev_level -= 1
+            stack[-1].append(TocEntry(anchor, title, []))
+
+        meta['toc'] = toc
diff --git a/packages/markdown-header-anchors/setup.cfg b/packages/markdown-header-anchors/setup.cfg
new file mode 100644
index 0000000..3c6e79c
--- /dev/null
+++ b/packages/markdown-header-anchors/setup.cfg
@@ -0,0 +1,2 @@
+[bdist_wheel]
+universal=1
diff --git a/packages/markdown-header-anchors/setup.py b/packages/markdown-header-anchors/setup.py
new file mode 100644
index 0000000..82f0955
--- /dev/null
+++ b/packages/markdown-header-anchors/setup.py
@@ -0,0 +1,40 @@
+import ast
+import io
+import re
+
+from setuptools import setup
+
+with io.open('README.md', 'rt', encoding="utf8") as f:
+    readme = f.read()
+
+_description_re = re.compile(r'description\s+=\s+(?P<description>.*)')
+
+with open('lektor_markdown_header_anchors.py', 'rb') as f:
+    description = str(ast.literal_eval(_description_re.search(
+        f.read().decode('utf-8')).group(1)))
+
+setup(
+    author='Armin Ronacher',
+    author_email='armin.ronacher at active-4.com',
+    description=description,
+    keywords='Lektor plugin markdown static-site blog toc table-of-contents anchors headers',
+    license='BSD',
+    long_description=readme,
+    long_description_content_type='text/markdown',
+    name='lektor-markdown-header-anchors',
+    py_modules=['lektor_markdown_header_anchors'],
+    url='http://github.com/lektor/lektor-markdown-header-anchors',
+    version='0.3.1',
+    classifiers=[
+        'Environment :: Plugins',
+        'Environment :: Web Environment',
+        'Framework :: Lektor',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: BSD License',
+    ],
+    entry_points={
+        'lektor.plugins': [
+            'markdown-header-anchors = lektor_markdown_header_anchors:MarkdownHeaderAnchorsPlugin',
+        ]
+    }
+)
diff --git a/templates/macros/contact.html b/templates/macros/contact.html
deleted file mode 100644
index 9a91967..0000000
--- a/templates/macros/contact.html
+++ /dev/null
@@ -1,3 +0,0 @@
-{% macro render_oftc() %}
-  <a href="https://webchat.oftc.net/" title="Tor Project IRC" target="_blank">OFTC IRC</a>
-{% endmacro %}
diff --git a/templates/macros/downloads.html b/templates/macros/downloads.html
deleted file mode 100644
index 2ceaef2..0000000
--- a/templates/macros/downloads.html
+++ /dev/null
@@ -1,48 +0,0 @@
-{% macro render_windows(version, alt) %}
-  {% set download_prefix = 'https://www.torproject.org/dist/torbrowser/' + version + '/' %}
-  {% if alt == 'en' %}
-    {% set alt = 'en-US' %}
-  {% endif %}
-  {% set download_link_64 = download_prefix + 'torbrowser-install-win64-' + version + '_' + alt + '.exe' %}
-  {% set download_link_32 = download_prefix + 'torbrowser-install-' + version + '_' + alt + '.exe' %}
-  {% set sig_link_64 = download_link_64 + '.asc' %}
-  {% set sig_link_32 = download_link_32 + '.asc' %}
-
-  <a class="downloadLink" href="{{ download_link_32 }}">32-bit</a> (<a href="{{ sig_link_32 }}">sig</a>) / <a href="{{ download_link_32 }}">64-bit</a> (<a href="{{ sig_link_64 }}">sig<a/>)
-{% endmacro %}
-
-{% macro render_mac(version, alt) %}
-  {% set download_prefix = 'https://www.torproject.org/dist/torbrowser/' + version + '/' %}
-  {% if alt == 'en' %}
-    {% set alt = 'en-US' %}
-  {% endif %}
-  {% set download_link = download_prefix + 'TorBrowser-' + version + '-osx64' + '_' + alt + '.dmg' %}
-  {% set sig_link = download_link + '.asc' %}
-
-  <a class="downloadLink" href="{{ download_link }}">64-bit</a> (<a href="{{ sig_link }}">sig</a>)
-{% endmacro %}
-
-{% macro render_linux(version, alt) %}
-  {% set download_prefix = 'https://www.torproject.org/dist/torbrowser/' + version + '/' %}
-  {% if alt == 'en' %}
-    {% set alt = 'en-US' %}
-  {% endif %}
-  {% set download_link_64 = download_prefix + 'tor-browser-linux64-' + version + '_' + alt + '.tar.xz' %}
-  {% set download_link_32 = download_prefix + 'tor-browser-linux32-' + version + '_' + alt + '.tar.xz' %}
-  {% set sig_link_64 = download_link_64 + '.asc' %}
-  {% set sig_link_32 = download_link_32 + '.asc' %}
-
-  <a class="downloadLink" href="{{ download_link_32 }}">32-bit</a> (<a href="{{ sig_link_32 }}">sig</a>) / <a href="{{ download_link_32 }}">64-bit</a> (<a href="{{ sig_link_64 }}">sig<a/>)
-{% endmacro %}
-
-{% macro render_fdroid() %}
-  <small class="badge-pill badge-dark mx-1 nick">S00N</small>
-{% endmacro %}
-
-{% macro render_onion_browser() %}
-  <a class="mx-auto" href=""><u>Onion Browser.</u></a>
-{% endmacro %}
-
-{% macro render_tor_browser_manual() %}
-  <a class="mx-auto" href="https://tb-manual.torproject.org" target="_blank"><u>tor browser manual</u></a>
-{% endmacro %}
diff --git a/templates/macros/jobs.html b/templates/macros/jobs.html
deleted file mode 100644
index 5adad47..0000000
--- a/templates/macros/jobs.html
+++ /dev/null
@@ -1,15 +0,0 @@
-{% macro render_active(item, alternative) %}
-<div class="card border-0">
-  <div class="card-header bg-white border-0" id="headingOne">
-    <h5 class="mb-0">
-      <a href="{{ item.path|url }}">{{ item.title }}</a>
-    </h5>
-  </div>
-  <div>
-    <div class="card-body">
-      {{ item.summary }}
-      <a href="{{ item.path|url }}">{{ _('Read more.') }}</a>
-    </div>
-  </div>
-</div>
-{% endmacro %}
diff --git a/templates/macros/people.html b/templates/macros/people.html
deleted file mode 100644
index 22b0121..0000000
--- a/templates/macros/people.html
+++ /dev/null
@@ -1,49 +0,0 @@
-{% macro render_board(item, alternative) %}
-  <div class="col-md-6 col-sm-12 col-xl-3 my-4">
-    <div class="card h-100 my-2">
-      <div class="card-body">
-        <h5 class="card-title human-name">{{ item.name }}</h5>
-        <h6 class="card-subtitle mb-2 text-primary nick text-capitalize">{{ item.title }}</h6>
-        <h6 class="card-subtitle mb-2 text-primary nick text-capitalize">{{ item.nickname }}{% if item.twitter_handle %} - <a href="https://twitter.com/{{ item.twitter_handle }}">@{{ item.twitter_handle }}</a>{% endif %}</h6>
-        {{ item.description }}
-      </div>
-    </div>
-  </div>
-{% endmacro %}
-
-{% macro render_core(item, alternative) %}
-  <div class="col-md-6 col-sm-12 col-xl-3 my-3">
-    <div class="card h-100">
-      <div class="card-header bg-white border-0">
-        {% if item.image %}
-          <picture>
-            <img src="{{ item.image|asseturl }}" class="rounded-circle float-left image-thumb" alt="{{ item.nickname }}">
-        {% else %}
-          <img src="{{ '/static/images/people/no_photo.png'|asseturl }}" class="rounded-circle float-left image-thumb" alt="no-photo">
-        {% endif %}
-        {% if item.twitter_handle %}
-          <a class="float-right py-4 px-2" href="https://twitter.com/{{ item.twitter_handle }}"><i class="fab fa-twitter"></i></a>
-        {% endif %}
-        {% if item.gpg %}
-          {% set link = site.get(item.gpg) %}
-          {% if link %}
-            <a class="float-right py-4 px-2" href="{{ item.gpg|asseturl }}">
-          {% else %}
-            <a class="float-right py-4 px-2" href="{{ item.gpg }}">
-          {% endif %}
-          <i class="fas fa-key"></i></a>
-        {% endif %}
-      </div>
-      <div class="card-body">
-      <h5 class="card-title human-name">{{ item.name }}</h5>
-      {% if item.pronoun %}
-        <h6 class="nick text-primary m-0">PRO:{{ item.pronoun }}</h6>
-      {% endif %}
-      {% if item.nickname %}
-        <label class="nick text-primary">IRC:{{ item.nickname }}</label>
-      {% endif %}
-      {{ item.description }}
-    </div>
-    </div>
-  </div>
-{% endmacro %}
diff --git a/templates/macros/press.html b/templates/macros/press.html
deleted file mode 100644
index 27707bf..0000000
--- a/templates/macros/press.html
+++ /dev/null
@@ -1,19 +0,0 @@
-{% macro render_release(item, alternative) %}
-<div class="card mx-auto" style="width: 365px; height: 485px;">
-  <img class="card-img-top" src="{{ '/static/images/index.svg'|asseturl }}" alt="Card image cap">
-  <div class="card-body">
-    <div class="card-title">
-      <a class="h4 text-primary" href="{{ item.link }}">{{ item.title }}</a>
-    </div>
-    <p class="card-text description">{{ item.summary }}</p>
-  </div>
-</div>
-{% endmacro %}
-
-{% macro render_snippet(item, alternative) %}
-<tr>
-  <th scope="row">{{ item.pub_date }}</th>
-  <td>{{ item.publisher }}</td>
-  <td><a class="h5 text-primary" href="{{ item.link }}">{{ item.title }}</a></td>
-</tr>
-{% endmacro %}
diff --git a/templates/macros/reports.html b/templates/macros/reports.html
deleted file mode 100644
index d9ccbe3..0000000
--- a/templates/macros/reports.html
+++ /dev/null
@@ -1,21 +0,0 @@
-{% macro render_document(item, alternative) %}
-<tr>
-  <td>{{ item.title }}</td>
-  <td>{{ item.description }}</td>
-  <td><a href="{{ item.link }}">{{ _('View PDF') }}</a></td>
-</tr>
-{% endmacro %}
-
-{% macro render_report(item, alternative) %}
-<tr>
-  <th scope="row">{{ item.date }}</th>
-  <td>
-    {% for tag in item.tags %}
-      {% set t = bag('tags', tag) %}
-      <span class="badge-pill badge-{{ t.color }}">{{ tag }}</span>
-    {% endfor %}
-  </td>
-  <td>{{ item.title }}</td>
-  <td><a href="{{ item.link }}">{{ _('View PDF') }}</a></td>
-</tr>
-{% endmacro %}
diff --git a/templates/macros/sponsors.html b/templates/macros/sponsors.html
deleted file mode 100644
index 377ca15..0000000
--- a/templates/macros/sponsors.html
+++ /dev/null
@@ -1,11 +0,0 @@
-{% macro render_active(item, alternative) %}
-<div class="col-md-4 col-xl-3 my-2">
-<div class="card border-1 h-100">
-  <img class="card-img-top" src="{{ item.logo|asseturl }}" alt="Card image cap">
-  <div class="card-body">
-    <h4><a href="{{ item.link }}">{{ item.name }}</a></h4>
-    {{ item.description }}
-  </div>
-</div>
-</div>
-{% endmacro %}





More information about the tor-commits mailing list