Przeglądaj źródła

add TODO to support archive.org-style urls

Nick Sweeting 1 rok temu
rodzic
commit
97b185987d
2 zmienionych plików z 8 dodań i 1 usunięć
  1. 1 0
      archivebox/core/urls.py
  2. 7 1
      archivebox/core/views.py

+ 1 - 0
archivebox/core/urls.py

@@ -20,6 +20,7 @@ urlpatterns = [
 
 
     path('archive/', RedirectView.as_view(url='/')),
     path('archive/', RedirectView.as_view(url='/')),
     path('archive/<path:path>', SnapshotView.as_view(), name='Snapshot'),
     path('archive/<path:path>', SnapshotView.as_view(), name='Snapshot'),
+    path('web/<path:path>', SnapshotView.as_view()),   # support archive.org-style URLs
 
 
     path('plugins/replaywebpage/', include('plugins.replaywebpage.urls')),
     path('plugins/replaywebpage/', include('plugins.replaywebpage.urls')),
     # ... dynamic load these someday if there are more of them
     # ... dynamic load these someday if there are more of them

+ 7 - 1
archivebox/core/views.py

@@ -56,12 +56,18 @@ class SnapshotView(View):
             slug, archivefile = path.split('/', 1)[0], 'index.html'
             slug, archivefile = path.split('/', 1)[0], 'index.html'
 
 
         # slug is a timestamp
         # slug is a timestamp
-        if slug.replace('.','').isdigit():
+        if slug.replace('.', '').isdigit():
 
 
             # missing trailing slash -> redirect to index
             # missing trailing slash -> redirect to index
             if '/' not in path:
             if '/' not in path:
                 return redirect(f'{path}/index.html')
                 return redirect(f'{path}/index.html')
 
 
+            # TODO: add support for archive.org-style URLs where timestamp may be a human-readable date
+            # https://web.archivebox.io / web / 2022-01 / https://example.com
+            # https://web.archivebox.io / web / 20220505103616 / https://example.com
+            # https://web.archivebox.io / web / 2022-05-05__0:36:16 / https://example.com
+            # use archivebox.util.parse_date (supports unix timestamps, iso date strings, and lots more etc.)
+
             try:
             try:
                 try:
                 try:
                     snapshot = Snapshot.objects.get(Q(timestamp=slug) | Q(id__startswith=slug))
                     snapshot = Snapshot.objects.get(Q(timestamp=slug) | Q(id__startswith=slug))