5 Commits 42c89708a9 ... dd54387cfd

Auteur SHA1 Message Date
  Iván Ruvalcaba dd54387cfd Merge branch 'master' of https://notabug.org/ploum/offpunk il y a 2 ans
  Lionel Dricot ab2271e6bf archiving regardless of the view used il y a 2 ans
  Iván Ruvalcaba 4c15cca81d Merge branch 'master' of https://notabug.org/ploum/offpunk il y a 2 ans
  Lionel Dricot c1981b4cf2 official repo il y a 2 ans
  Lionel Dricot 10ab7323bd do not try to render non-image files with chafa to avoid errors il y a 2 ans
3 fichiers modifiés avec 18 ajouts et 4 suppressions
  1. 2 0
      CHANGELOG
  2. 4 2
      README.md
  3. 12 2
      offpunk.py

+ 2 - 0
CHANGELOG

@@ -3,7 +3,9 @@
 ## 1.4 - Unreleased
 - Making python-readability optional
 - Removing "next" and "previous" which are quite confusing and not obvious
+- Archiving now works regardless of the view you are in.
 - Fixing a crash when accessing an empty html page
+- Not trying to display non-image files to avoid errors. (this requires "file")
 
 ## 1.3 - April 2th 2022
 - Removed dependency to python-magic. File is now used directly (and should be on every system).

+ 4 - 2
README.md

@@ -4,6 +4,8 @@ A command-line and offline-first smolnet browser/feed reader for Gemini, Gopher,
 
 The goal of Offpunk is to be able to synchronise your content once (a day, a week, a month) and then browse/organise it while staying disconnected.
 
+Official repository : https://notabug.org/ploum/offpunk/
+
 ![Screenshot HTML page with picture](/screenshot_offpunk1.png)
 ![Screenshot Gemini page](/screenshot_offpunk2.png)
 
@@ -78,9 +80,9 @@ To avoid using unstable or too recent libraries, the rule of thumb is that a lib
 
 Run command `version` in offpunk to see if you are missing some dependencies.
 
-Highly recommended (packagers should probably make those mandatory):
+Mandatory or highly recommended (packagers should probably make those mandatory):
 * [less](http://www.greenwoodsoftware.com/less/): mandatory but is probably already on your system
-* [file](https://www.darwinsys.com/file/) is used to get the MIME type of cached objects. Should already be on your system.
+* [file](https://www.darwinsys.com/file/) is used to get the MIME type of cached objects. Should already be on your system and may become mandatory.
 * [xdg-utils](https://www.freedesktop.org/wiki/Software/xdg-utils/) provides xdg-open which is highly recommended to open files without a renderer or a handler. It is also used for mailto: command.
 * The [cryptography library](https://pypi.org/project/cryptography/) will provide a better and slightly more secure experience when using the default TOFU certificate validation mode and is highly recommended (apt-get install python3-cryptography).
 

+ 12 - 2
offpunk.py

@@ -105,6 +105,11 @@ def inline_image(img_file,width):
     #Chafa is faster than timg inline. Let use that one by default
     inline = None
     ansi_img = ""
+    #We avoid errors by not trying to render non-image files
+    if shutil.which("file"):
+        mime = run("file -b --mime-type \"%s\""%img_file).strip()
+        if not "image" in mime:
+            return ansi_img
     if _HAS_CHAFA:
         if _HAS_PIL and not _NEW_CHAFA:
             # this code is a hack to remove frames from animated gif
@@ -3637,13 +3642,18 @@ archives, which is a special historical list limited in size. It is similar to `
                 lines = lf.readlines()
                 lf.close()
             to_write = []
+            # let’s remove the mode
+            url = url.split("##offpunk_mode=")[0]
             for l in lines:
                 # we separate components of the line
                 # to ensure we identify a complete URL, not a part of it
                 splitted = l.split()
-                if url not in splitted:
+                if url not in splitted and len(splitted) > 0:
+                    current = splitted[1].split("##offpunk_mode=")[0]
                     #sometimes, we must remove the ending "/"
-                    if url.endswith("/") and url[:-1] in splitted:
+                    if url == current:
+                        to_return = True
+                    elif url.endswith("/") and url[:-1] == current:
                         to_return = True
                     else:
                         to_write.append(l)