Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update npf-renderer to 0.13.0 #85

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ body {
--color-poll-proportion-bar-bg: var(--light, var(--color-gray-250)) var(--dark, var(--color-dt-gray-300));
--color-poll-choice-bg: var(--light, var(--color-gray-150)) var(--dark, var(--color-dt-gray-500));

--color-post-reveal-truncated-content-button: var(--light, var(--color-primary-500)) var(--dark, var(--color-primary-700));
--color-post-reveal-truncated-content-button-hover: var(--light, var(--color-primary-400)) var(--dark, var(--color-primary-600));

--color-post-footer: var(--light, var(--color-gray-500)) var(--dark, var(--color-dt-gray-250));
--color-post-footer-post-interaction: var(--light, var(--color-gray-500)) var(--dark, var(--color-dt-gray-225));
--color-post-tag-bg: var(--light, var(--color-gray-125)) var(--dark, var(--color-dt-gray-575));
Expand Down
30 changes: 29 additions & 1 deletion assets/css/post-layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,39 @@

.post-body > .text-block:last-child,
.post-body > .layout-row:last-child > .text-block:last-child,
.post-body > .layout-truncated:last-child > .text-block:last-child,
.post-body > .link-block:last-child,
.post-body > .layout-row:last-child > .link-block:last-child {
.post-body > .layout-row:last-child > .link-block:last-child
.post-body > .layout-truncated:last-child > .text-block:last-child {
margin-bottom: 0;
}

.layout-row {
margin: 0;
}

.layout-truncated > summary {
color: var(--color-post-reveal-truncated-content-button);
list-style: none;
font-weight: 650;
cursor: pointer;
text-decoration: underline;
display: inline-block;

position: relative;
left: 50%;
transform: translateX(-50%);
}

.layout-truncated > summary:hover {
color: var(--color-post-reveal-truncated-content-button-hover);
}

.layout-truncated[open=""] > summary {
display: none;
}


.heading1, .heading2, .quote {
font-weight: 500;
}
Expand Down
6 changes: 3 additions & 3 deletions assets/js/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function fill_poll_results(poll_element, results) {
}

const answerIdChoiceElementArray = [];
const pollBody = poll_element.getElementsByClassName("poll-body")[0];
const pollChoices = poll_element.getElementsByClassName("poll-choices")[0];

for (let choiceElement of pollBody.children) {
for (let choiceElement of pollChoices.children) {
answerIdChoiceElementArray.push([choiceElement.dataset.answerId, choiceElement]);
}

Expand All @@ -63,7 +63,7 @@ function fill_poll_results(poll_element, results) {
voteProportionElement.classList.add("vote-proportion");
voteProportionElement["style"] = `width: ${((numericalVoteProportion) * 100).toFixed(3)}%;`;

const voteCountElement = document.createElement("span");
const voteCountElement = document.createElement("p");
voteCountElement.classList.add("vote-count");

// A greater rounding precision is needed here
Expand Down
84 changes: 84 additions & 0 deletions locales/en_US/LC_MESSAGES/npf_renderer.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright (C) 2023 Syeopite
# This file is distributed under the same license as the Priviblur project.
# syeopite <[email protected]>, 2023
#
msgid ""
msgstr ""
"Project-Id-Version: Priviblur v0.3.0-dev\n"
"Report-Msgid-Bugs-To: https://github.com/syeopite/priviblur/issues\n"
"POT-Creation-Date: 2023-11-16 00:07-0800\n"
"PO-Revision-Date: 2024-06-29 04:09+0000\n"
"Last-Translator: syeopite <[email protected]>\n"
"Language-Team: English <https://hosted.weblate.org/projects/priviblur/"
"translations/en/>\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.7-dev\n"

msgid "asker_with_no_attribution"
msgstr "Anonymous"

msgid "asker_and_ask_verb"
msgstr "{name} asked"

msgid "unsupported_block_header"
msgstr "Unsupported NPF block"

msgid "unsupported_block_description"
msgstr "Placeholder for the unsupported \"{block}\" type NPF block Please report me over at https://github.com/syeopite/npf-renderer"

msgid "generic_image_alt_text"
msgstr "image"

msgid "link_block_poster_alt_text"
msgstr "Preview image for \"{site}\""

msgid "link_block_fallback_embeds_are_disabled"
msgstr "Embeds are disabled"

msgid "error_video_link_block_fallback_heading"
msgstr "Error: unable to render video block"

msgid "video_link_block_fallback_description"
msgstr "Please click me to watch on the original site"

msgid "error_link_block_fallback_native_video_player_non_tumblr_source"
msgstr "Error: non-tumblr source for video player"

msgid "fallback_audio_block_thumbnail_alt_text"
msgstr "Album art"

msgid "error_audio_link_block_fallback_heading"
msgstr "Error: unable to render audio block"

msgid "audio_link_block_fallback_description"
msgstr "Please click me to listen on the original site"

msgid "error_link_block_fallback_native_audio_player_non_tumblr_source"
msgstr "Error: non-tumblr source for audio player"

msgid "poll_total_votes"
msgid_plural "poll_total_votes_plural"
msgstr[0] "{votes} vote"
msgstr[1] "{votes} votes"

msgid "poll_remaining_time"
msgstr "{duration} remaining"

msgid "poll_ended_on"
msgstr "Ended on: {ended_date}"

msgid "post_attribution"
msgstr "From {0}"

msgid "blog_attribution"
msgstr "Created by {0}"

msgid "app_attribution"
msgstr "View on {0}"

msgid "unsupported_attribution"
msgstr "Attributed via an unsupported (\"{0}\") attribution type. Please report this over at https://github.com/syeopite/npf-renderer"
8 changes: 7 additions & 1 deletion locales/en_US/LC_MESSAGES/priviblur.po
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,10 @@ msgid "post_note_viewer_view_replies_filter_sort_oldest"
msgstr "Oldest first"

msgid "post_note_viewer_view_replies_filter_sort_newest"
msgstr "Newest first"
msgstr "Newest first"

msgid "settings_expand_blogger_truncated_posts"
msgstr "Expand posts"

msgid "settings_expand_blogger_truncated_posts_desc"
msgstr "Expands truncated posts automatically"
1 change: 1 addition & 0 deletions src/config/user_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ class DefaultUserPreferences(NamedTuple):

language: str = "en_US"
theme: str = "auto"
expand_posts: bool = False
42 changes: 37 additions & 5 deletions src/helpers/ext_npf_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,30 @@ async def parse(self):


class NPFFormatter(npf_renderer.format.Formatter):
def __init__(self, content, layout=None, blog_name=None, post_id=None, *, url_handler=None, forbid_external_iframes=False):
super().__init__(content, layout, url_handler=url_handler, forbid_external_iframes=forbid_external_iframes)
def __init__(
self,
content,
layout=None,
*,
blog_name=None,
post_id=None,
url_handler=None,
forbid_external_iframes=False,
request=None,
):
initialization_arguments = {
"content": content,
"layout": layout,
"url_handler": url_handler,
"forbid_external_iframes": forbid_external_iframes
}

if request:
# Asking to expand a post is the reverse of asking to truncate a post
initialization_arguments["truncate"] = not request.ctx.preferences.expand_posts
initialization_arguments["localizer"] = request.app.ctx.LANGUAGES[request.ctx.language].npf_renderer_localizer

super().__init__(**initialization_arguments)

# We store the blog and post ID as to be able to render a link to
# fetch poll results for JS disabled users
Expand All @@ -114,9 +136,9 @@ def _format_poll(self, block):
poll_html = super()._format_poll(block)
poll_html["data-poll-id"] = block.poll_id

poll_body = poll_html[1]
poll_choices = poll_html[1][0]
for index, answer_id in enumerate(block.answers.keys()):
poll_body[index]["data-answer-id"] = answer_id
poll_choices[index]["data-answer-id"] = answer_id

if (self.blog_name and self.post_id) and not block.votes:
poll_footer = poll_html[2]
Expand Down Expand Up @@ -171,7 +193,14 @@ def _add_alt_text_element(self, block, image_container):
)


async def format_npf(contents, layouts=None, blog_name=None, post_id=None,*, poll_callback=None):
async def format_npf(
contents,
layouts=None,
blog_name=None,
post_id=None,*,
poll_callback=None,
request=None
):
"""Wrapper around npf_renderer.format_npf for extra functionalities

- Replaces internal Parser and Formatter with the modified variants above
Expand All @@ -183,6 +212,8 @@ async def format_npf(contents, layouts=None, blog_name=None, post_id=None,*, pol
Name of the blog the post comes from. This is used to render links to the parent post
post_id:
Unique ID of the post. This is used to render links to the parent post
request:
Sanic request object. Used to check user preferences
"""
try:
contents = await NPFParser(contents, poll_callback=poll_callback).parse()
Expand All @@ -197,6 +228,7 @@ async def format_npf(contents, layouts=None, blog_name=None, post_id=None,*, pol
post_id=post_id,
url_handler=url_handler,
forbid_external_iframes=True,
request=request
).format()

except npf_renderer.exceptions.RenderErrorDisclaimerError as e:
Expand Down
73 changes: 0 additions & 73 deletions src/helpers/i18n.py

This file was deleted.

1 change: 1 addition & 0 deletions src/i18n/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .i18n import SUPPORTED_LANGUAGES, initialize_locales, translate
Loading
Loading