diff --git a/README.md b/README.md index 56afe775..b8be5bce 100644 --- a/README.md +++ b/README.md @@ -422,6 +422,8 @@ git clone https://github.com/ArchiveBox/ArchiveBox cd ArchiveBox git checkout master # or the branch you want to test git pull +git submodule init +git submodule update # Install ArchiveBox + python dependencies python3 -m venv .venv && source .venv/bin/activate && pip install -e .[dev] diff --git a/archivebox/core/views.py b/archivebox/core/views.py index aaef74e2..a81d98f3 100644 --- a/archivebox/core/views.py +++ b/archivebox/core/views.py @@ -94,6 +94,7 @@ class PublicArchiveView(ListView): template = 'snapshot_list.html' model = Snapshot paginate_by = 100 + ordering = ['title'] def get_context_data(self, **kwargs): return { @@ -106,7 +107,7 @@ class PublicArchiveView(ListView): qs = super().get_queryset(**kwargs) query = self.request.GET.get('q') if query: - qs = Snapshot.objects.filter(title__icontains=query) + qs = qs.filter(title__icontains=query) for snapshot in qs: snapshot.icons = snapshot_icons(snapshot) return qs diff --git a/archivebox/index/html.py b/archivebox/index/html.py index b793cea3..04340957 100644 --- a/archivebox/index/html.py +++ b/archivebox/index/html.py @@ -1,6 +1,5 @@ __package__ = 'archivebox.index' -from string import Template from datetime import datetime from typing import List, Optional, Iterator, Mapping from pathlib import Path @@ -20,18 +19,16 @@ from ..util import ( ) from ..config import ( OUTPUT_DIR, - TEMPLATES_DIR, VERSION, GIT_SHA, FOOTER_INFO, - ARCHIVE_DIR_NAME, HTML_INDEX_FILENAME, + setup_django, ) -MAIN_INDEX_TEMPLATE = str(Path(TEMPLATES_DIR) / 'main_index.html') -MINIMAL_INDEX_TEMPLATE = str(Path(TEMPLATES_DIR) / 'main_index_minimal.html') -MAIN_INDEX_ROW_TEMPLATE = str(Path(TEMPLATES_DIR) / 'main_index_row.html') -LINK_DETAILS_TEMPLATE = str(Path(TEMPLATES_DIR) / 'link_details.html') +MAIN_INDEX_TEMPLATE = 'main_index.html' +MINIMAL_INDEX_TEMPLATE = 'main_index_minimal.html' +LINK_DETAILS_TEMPLATE = 'link_details.html' TITLE_LOADING_MSG = 'Not yet archived...' @@ -49,51 +46,18 @@ def parse_html_main_index(out_dir: Path=OUTPUT_DIR) -> Iterator[str]: yield line.split('"')[1] return () - @enforce_types def main_index_template(links: List[Link], template: str=MAIN_INDEX_TEMPLATE) -> str: """render the template for the entire main index""" - return render_legacy_template(template, { + return render_django_template(template, { 'version': VERSION, 'git_sha': GIT_SHA, 'num_links': str(len(links)), 'date_updated': datetime.now().strftime('%Y-%m-%d'), 'time_updated': datetime.now().strftime('%Y-%m-%d %H:%M'), - 'rows': '\n'.join( - main_index_row_template(link) - for link in links - ), - 'footer_info': FOOTER_INFO, - }) - - -@enforce_types -def main_index_row_template(link: Link) -> str: - """render the template for an individual link row of the main index""" - - from ..extractors.wget import wget_output_path - - return render_legacy_template(MAIN_INDEX_ROW_TEMPLATE, { - **link._asdict(extended=True), - - # before pages are finished archiving, show loading msg instead of title - 'title': htmlencode( - link.title - or (link.base_url if link.is_archived else TITLE_LOADING_MSG) - ), - - # before pages are finished archiving, show fallback loading favicon - 'favicon_url': ( - str(Path(ARCHIVE_DIR_NAME) / link.timestamp / 'favicon.ico') - # if link['is_archived'] else 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=' - ), - - # before pages are finished archiving, show the details page instead - 'wget_url': urlencode(wget_output_path(link) or 'index.html'), - - # replace commas in tags with spaces, or file extension if it's static - 'tags': (link.tags or '') + (' {}'.format(link.extension) if link.is_static else ''), + 'links': [link._asdict(extended=True) for link in links], + 'FOOTER_INFO': FOOTER_INFO, }) @@ -114,7 +78,7 @@ def link_details_template(link: Link) -> str: link_info = link._asdict(extended=True) - return render_legacy_template(LINK_DETAILS_TEMPLATE, { + return render_django_template(LINK_DETAILS_TEMPLATE, { **link_info, **link_info['canonical'], 'title': htmlencode( @@ -134,17 +98,13 @@ def link_details_template(link: Link) -> str: 'oldest_archive_date': ts_to_date(link.oldest_archive_date), }) - @enforce_types -def render_legacy_template(template_path: str, context: Mapping[str, str]) -> str: +def render_django_template(template: str, context: Mapping[str, str]) -> str: """render a given html template string with the given template content""" + from django.template.loader import render_to_string - # will be replaced by django templates in the future - with open(template_path, 'r', encoding='utf-8') as template: - template_str = template.read() - return Template(template_str).substitute(**context) - - + setup_django(check_db=False) + return render_to_string(template, context) def snapshot_icons(snapshot) -> str: diff --git a/archivebox/themes/default/core/snapshot_list.html b/archivebox/themes/default/core/snapshot_list.html index 73761372..ce2b2faa 100644 --- a/archivebox/themes/default/core/snapshot_list.html +++ b/archivebox/themes/default/core/snapshot_list.html @@ -18,40 +18,27 @@ Original URL - - {% for link in object_list %} - - {{link.added}} - - {% if link.is_archived %} - - {% else %} - - {% endif %} - - {{link.title|default:'Loading...'}} - {{link.tags_str}} - - - - {{link.icons}} - - - {{link.url}} - - - {% endfor %} - - -
- - {% if page_obj.has_previous %} - « first - previous - {% endif %} - - - Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}. + + {% for link in object_list %} + {% include 'main_index_row.html' with link=link %} + {% endfor %} + + +
+ + {% if page_obj.has_previous %} + « first + previous + {% endif %} + + + Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}. + + + {% if page_obj.has_next %} + next + last » + {% endif %} {% if page_obj.has_next %} diff --git a/archivebox/themes/legacy/link_details.html b/archivebox/themes/default/link_details.html similarity index 80% rename from archivebox/themes/legacy/link_details.html rename to archivebox/themes/default/link_details.html index efb7274b..b1edcfe0 100644 --- a/archivebox/themes/legacy/link_details.html +++ b/archivebox/themes/default/link_details.html @@ -1,7 +1,7 @@ - $title + {{title}}