mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 22:54:27 -04:00
feat: Re-add unused icons in list view
This commit is contained in:
parent
f84f288bef
commit
f61e6a74bb
2 changed files with 24 additions and 24 deletions
|
@ -1,4 +1,5 @@
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from core.models import Snapshot, EXTRACTORS
|
from core.models import Snapshot, EXTRACTORS
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -7,9 +8,10 @@ from pathlib import Path
|
||||||
def get_icons(snapshot: Snapshot) -> str:
|
def get_icons(snapshot: Snapshot) -> str:
|
||||||
archive_results = snapshot.archiveresult_set.filter(status="succeeded")
|
archive_results = snapshot.archiveresult_set.filter(status="succeeded")
|
||||||
link = snapshot.as_link()
|
link = snapshot.as_link()
|
||||||
|
path = link.archive_path
|
||||||
canon = link.canonical_outputs()
|
canon = link.canonical_outputs()
|
||||||
output = ""
|
output = ""
|
||||||
output_template = '<a href="/{}/{}" class="exists-True" title="{}">{} </a>'
|
output_template = '<a href="/{}/{}" class="exists-{}" title="{}">{} </a>'
|
||||||
icons = {
|
icons = {
|
||||||
"singlefile": "❶",
|
"singlefile": "❶",
|
||||||
"wget": "🆆",
|
"wget": "🆆",
|
||||||
|
@ -23,34 +25,31 @@ def get_icons(snapshot: Snapshot) -> str:
|
||||||
"mercury": "🅼",
|
"mercury": "🅼",
|
||||||
"warc": "📦"
|
"warc": "📦"
|
||||||
}
|
}
|
||||||
exclude = ["favicon", "archive_org"]
|
exclude = ["favicon", "title", "headers", "archive_org"]
|
||||||
# Missing specific entry for WARC
|
# Missing specific entry for WARC
|
||||||
|
|
||||||
|
extractor_items = defaultdict(lambda: None)
|
||||||
for extractor, _ in EXTRACTORS:
|
for extractor, _ in EXTRACTORS:
|
||||||
for result in archive_results:
|
for result in archive_results:
|
||||||
if result.extractor != extractor:
|
if result.extractor == extractor:
|
||||||
continue
|
extractor_items[extractor] = result
|
||||||
path = link.archive_path
|
|
||||||
try:
|
|
||||||
if extractor not in exclude:
|
|
||||||
output += output_template.format(path, canon[f"{extractor}_path"],
|
|
||||||
extractor, icons.get(extractor, "?"))
|
|
||||||
if extractor == "wget":
|
|
||||||
# warc isn't technically it's own extractor, so we have to add it after wget
|
|
||||||
exists = list((Path(path) / canon["warc_path"]).glob("*.warc.gz"))
|
|
||||||
if exists:
|
|
||||||
output += output_template.format(exists[0], "",
|
|
||||||
"warc", icons.get("warc", "?"))
|
|
||||||
|
|
||||||
if extractor == "archive_org":
|
for extractor, _ in EXTRACTORS:
|
||||||
# The check for archive_org is different, so it has to be handled separately
|
if extractor not in exclude:
|
||||||
target_path = Path(path) / "archive.org.txt"
|
exists = extractor_items[extractor] is not None
|
||||||
exists = target_path.exists()
|
output += output_template.format(path, canon[f"{extractor}_path"], str(exists),
|
||||||
if exists:
|
extractor, icons.get(extractor, "?"))
|
||||||
output += '<a href="{}" class="exists-True" title="{}">{} </a>'.format(canon["archive_org_path"],
|
if extractor == "wget":
|
||||||
"archive_org", icons.get("archive_org", "?"))
|
# warc isn't technically it's own extractor, so we have to add it after wget
|
||||||
|
exists = list((Path(path) / canon["warc_path"]).glob("*.warc.gz"))
|
||||||
|
if exists:
|
||||||
|
output += output_template.format(exists[0], "", str(bool(exists)), "warc", icons.get("warc", "?"))
|
||||||
|
|
||||||
except Exception as e:
|
if extractor == "archive_org":
|
||||||
print(e)
|
# The check for archive_org is different, so it has to be handled separately
|
||||||
|
target_path = Path(path) / "archive.org.txt"
|
||||||
|
exists = target_path.exists()
|
||||||
|
output += '<a href="{}" class="exists-{}" title="{}">{} </a>'.format(canon["archive_org_path"], str(exists),
|
||||||
|
"archive_org", icons.get("archive_org", "?"))
|
||||||
|
|
||||||
return format_html(f'<span class="files-icons" style="font-size: 1.2em; opacity: 0.8">{output}<span>')
|
return format_html(f'<span class="files-icons" style="font-size: 1.2em; opacity: 0.8">{output}<span>')
|
||||||
|
|
|
@ -226,6 +226,7 @@
|
||||||
|
|
||||||
.exists-False {
|
.exists-False {
|
||||||
opacity: 0.1;
|
opacity: 0.1;
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="{% static 'bootstrap.min.css' %}">
|
<link rel="stylesheet" href="{% static 'bootstrap.min.css' %}">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue