From 8e0ef7be226eb9ca7316fffa1c8f8e3f527f709a Mon Sep 17 00:00:00 2001 From: Eliot Berriot <contact@eliotberriot.com> Date: Fri, 24 May 2019 19:13:18 +0200 Subject: [PATCH] Include the source doc in generated HTML --- retribute_me/cli.py | 6 +- retribute_me/templates/profile.jinja2 | 7 +- test.html | 131 ++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 test.html diff --git a/retribute_me/cli.py b/retribute_me/cli.py index 7a407c2..baa0a60 100644 --- a/retribute_me/cli.py +++ b/retribute_me/cli.py @@ -56,9 +56,8 @@ def get_template_context(document): @cli.command() @click.argument("document", type=click.File("r")) -@click.argument("output", type=click.File("w")) @click.option("--template", "-t", type=click.File("r")) -def html(document, output, template): +def html(document, template): content = document.read() document = json.loads(content) context = get_template_context(document) @@ -73,7 +72,8 @@ def html(document, output, template): "{% autoescape true %}" + template_content + "{% endautoescape %}", undefined=jinja2.StrictUndefined, ) - click.echo(t.render(**context)) + output = t.render(**context) + click.echo(output) if __name__ == "__main__": diff --git a/retribute_me/templates/profile.jinja2 b/retribute_me/templates/profile.jinja2 index c80aa43..e365240 100644 --- a/retribute_me/templates/profile.jinja2 +++ b/retribute_me/templates/profile.jinja2 @@ -24,7 +24,7 @@ <article> <h3> {%- if identity.url %} - <a href="{{ identity.url }}" rel="me noopener"> + <a href="{{ identity.url }}" rel="retribute me noopener"> {{ identity.get_full_name() }} </a> {%- else %} @@ -45,7 +45,7 @@ <article class="mean"> <h3> {%- if mean.url %} - <a href="{{ mean.url }}" rel="me noopener"> + <a href="{{ mean.url }}" rel="retribute me noopener"> {{ mean.get_full_name() }} </a> {%- else %} @@ -60,5 +60,8 @@ </section> {%- endif %} </main> + <script type="application/retribute+json"> + {{ doc|tojson(indent=2) }} + </script> </body> </html> diff --git a/test.html b/test.html new file mode 100644 index 0000000..6666293 --- /dev/null +++ b/test.html @@ -0,0 +1,131 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width,initial-scale=1.0"> + <title>Caring is loving</title> + <meta name="description" content="My name is Alice, I produce Creative Commons electro music. I need your support to continue working on my audio pieces!" /> + + </head> + <body> + <header> + <h1>Caring is loving</h1> + <p>My name is Alice, I produce Creative Commons electro music. I need your support to continue working on my audio pieces!</p> + + </header> + <main> + <section class="identity"> + <h2>My other identities</h2> + + <article> + <h3> + <a href="https://alice.me" rel="retribute me noopener"> + My personal website + </a> + </h3> + </article> + + <article> + <h3> + <a href="https://musicbrainz.org/artist/176216c5-d6e7-4df1-83cf-85251328eb90" rel="retribute me noopener"> + 176216c5-d6e7-4df1-83cf-85251328eb90 on musicbrainz + </a> + </h3> + </article> + + <article> + <h3> + <a href="https://mastodon.instance/alice" rel="retribute me noopener"> + alice@mastodon.instance on fediverse + </a> + </h3> + </article> + + </section> + <section> + <h2>Support me!</h2> + + <article class="mean"> + <h3> + <a href="https://freetips.com/@Alice" rel="retribute me noopener"> + Tip me on freetips + </a> + </h3> + <p>This is the best place to tip me</p> + </article> + + <article class="mean"> + <h3> + Cash + </h3> + <p>I live here, you can send me money directly</p> + </article> + + <article class="mean"> + <h3> + <a href="https://flattr.com/@Alice" rel="retribute me noopener"> + Alice on flattr + </a> + </h3> + </article> + + </section> + </main> + <script type="application/json+retribute"> + { + "id": "https://retribute.me/@Alice.json", + "identities": [ + { + "id": "alice@mastodon.instance", + "provider": "fediverse", + "url": "https://mastodon.instance/alice", + "weight": 1 + }, + { + "id": "176216c5-d6e7-4df1-83cf-85251328eb90", + "provider": "musicbrainz", + "url": "https://musicbrainz.org/artist/176216c5-d6e7-4df1-83cf-85251328eb90", + "weight": 2 + }, + { + "id": "personal-website", + "name": "My personal website", + "provider": "custom", + "url": "https://alice.me", + "weight": 3 + } + ], + "means": [ + { + "id": "Alice", + "provider": "flattr", + "url": "https://flattr.com/@Alice", + "weight": 0 + }, + { + "id": "sendmecash", + "name": "Cash", + "provider": "custom", + "summary": "I live here, you can send me money directly", + "weight": 1 + }, + { + "id": "freetips", + "name": "Tip me on freetips", + "provider": "unknown", + "summary": "This is the best place to tip me", + "url": "https://freetips.com/@Alice", + "weight": 2 + } + ], + "summary": "My name is Alice, I produce Creative Commons electro music. I need your support to continue working on my audio pieces!", + "title": "Caring is loving", + "updated": "2019-05-24T18:56:12.269457", + "url": "https://retribute.me/@Alice.html", + "version": "0.1" +} + </script> + </body> +</html> + -- GitLab