~sircmpwn/sr.ht-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH paste.sr.ht] Switch to dir="auto" and improve performance on file renderer

Details
Message ID
<20231204124620.1391278-1-vcs@ersei.net>
DKIM signature
missing
Download raw message
Patch: +35 -6
Same changes from the patches sent to git.sr.ht with an external line
counter and other small changes as well as a 512KB limit on file sizes
being rendered
---
 pastesrht/blueprints/public.py     |  8 +++++++-
 pastesrht/templates/new-paste.html |  2 ++
 pastesrht/templates/paste.html     | 30 +++++++++++++++++++++++++-----
 pastesrht/templates/pastes.html    |  1 +
 4 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/pastesrht/blueprints/public.py b/pastesrht/blueprints/public.py
index 08debee..497914e 100644
--- a/pastesrht/blueprints/public.py
+++ b/pastesrht/blueprints/public.py
@@ -140,6 +140,12 @@ def highlight_file(name, content):
    html = f"<style>{style}</style>" + highlight(content, lexer, formatter)
    return Markup(html)

def linecounter(count):
    out = []
    for i in range(1, count + 1):
        out.append('<a href="#L{}" id="L{}">{}\n</a>'.format(i, i, i))
    return "".join(out)

@public.route("/~<user>")
def pastes_user(user):
    user = get_user_or_abort(user)
@@ -165,7 +171,7 @@ def pastes_user(user):
def paste_GET(user, sha):
    user, paste = get_paste_or_abort(user, sha)
    return render_template("paste.html", paste=paste,
            highlight_file=highlight_file)
            highlight_file=highlight_file, linecounter=linecounter)

@public.route("/~<user>/<sha>/manage")
def paste_manage(user, sha):
diff --git a/pastesrht/templates/new-paste.html b/pastesrht/templates/new-paste.html
index e828840..a3d818d 100644
--- a/pastesrht/templates/new-paste.html
+++ b/pastesrht/templates/new-paste.html
@@ -21,6 +21,7 @@
      <div class="form-group">
        <input
          type="text"
          dir="auto"
          id="filename"
          name="filename"
          class="form-control {{valid.cls('filename')}}"
@@ -30,6 +31,7 @@
      </div>
      <div class="form-group">
        <textarea
          dir="auto"
          name="contents"
          id="contents"
          class="form-control {{valid.cls('contents')}}"
diff --git a/pastesrht/templates/paste.html b/pastesrht/templates/paste.html
index 3ddcd4b..df616d9 100644
--- a/pastesrht/templates/paste.html
+++ b/pastesrht/templates/paste.html
@@ -40,15 +40,35 @@
</div>
{% else %}
<div class="container-fluid other-content">
{% if len(file.blob.contents) > 512000 %}
    <div class="col-md-12">
      <div style="padding: 1rem">
        <p>
          <span title="{{ len(file.blob.contents) }} bytes">
            {{humanize.naturalsize(len(file.blob.contents),
              binary=True).replace("Byte", "byte")}}
          </span>
          large file not shown.
        </p>
        <p>
          <a href="{{ url_for(".blob_GET", sha=file.blob.sha) }}"
              class="btn btn-primary"
              rel="nofollow"
          >Download {{icon("caret-right")}}</a>
        </p>
      </div>
    </div>

{% else %}
  <div class="code-view">
    {% autoescape off %}
    <pre class="ruler"><span>{% for i in range(80) %} {% endfor %}</span></pre>
    <pre class="lines">{% for line in file.blob.contents.split("\n") %}<a
      href="#{{file.filename}}-L{{loop.index}}"
      id="{{file.filename}}-L{{loop.index}}"
      >{{loop.index}}</a>{% if not loop.last %}
{% endif %}{% endfor %}</pre>
    {% set lines = file.blob.contents.splitlines()|length %}
    <pre class="lines">{{ linecounter(lines) }}</pre>
    {% endautoescape %}
    {{highlight_file(file.filename or "", file.blob.contents)}}
  </div>
{% endif %}
</div>
{% endif %}
{% endfor %}
diff --git a/pastesrht/templates/pastes.html b/pastesrht/templates/pastes.html
index 1793d0a..88475a7 100644
--- a/pastesrht/templates/pastes.html
+++ b/pastesrht/templates/pastes.html
@@ -39,6 +39,7 @@
      <input
        name="search"
        type="text"
        dir="auto"
        placeholder="Search pastes...     filename     visibility:unlisted     sha:d54e32b"
        class="form-control{% if search_error %} is-invalid{% endif %}"
        value="{{ search if search else "" }}" />
-- 
2.42.0

[paste.sr.ht/patches] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CXFKAOW6SS0A.1B6BBFY8NR2FF@cirno2>
In-Reply-To
<20231204124620.1391278-1-vcs@ersei.net> (view parent)
DKIM signature
missing
Download raw message
paste.sr.ht/patches: FAILED in 5m19s

[Switch to dir="auto" and improve performance on file renderer][0] from [Ersei Saggi][1]

[0]: https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/47349
[1]: vcs@ersei.net

✗ #1107298 FAILED  paste.sr.ht/patches/archlinux.yml https://builds.sr.ht/~sircmpwn/job/1107298
✓ #1107297 SUCCESS paste.sr.ht/patches/alpine.yml    https://builds.sr.ht/~sircmpwn/job/1107297
✓ #1107299 SUCCESS paste.sr.ht/patches/debian.yml    https://builds.sr.ht/~sircmpwn/job/1107299
Reply to thread Export thread (mbox)