Repository: getnikola/nikola

Issue:
Generate a single archive, rather than per-year
I have very few posts in my site, so having a per-year archive doesn't make any sense.  I would really like to have an option to list all posts in one page.



Discussion:
I would like this as well. I've been meaning to have a look at the code, but haven't had time. Would probably need a decent refactoring of archive.py, and some extra options in the config. 

It shouldn’t be that hard to do this.  One if, and maybe ten more lines of code.  Assigning myself.


Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -87,6 +87,7 @@ def __init__(self, **config):
 
         self.strict = False
         self.global_data = {}
+        self.posts = []
         self.posts_per_year = defaultdict(list)
         self.posts_per_month = defaultdict(list)
         self.posts_per_tag = defaultdict(list)
@@ -129,6 +130,7 @@ def __init__(self, **config):
             'CONTENT_FOOTER': '',
             'COPY_SOURCES': True,
             'CREATE_MONTHLY_ARCHIVE': False,
+            'CREATE_SINGLE_ARCHIVE': False,
             'DATE_FORMAT': '%Y-%m-%d %H:%M',
             'DEFAULT_LANG': "en",
             'DEPLOY_COMMANDS': [],
@@ -839,6 +841,7 @@ def scan_posts(self):
                     )
                     self.global_data[post.source_path] = post
                     if post.use_in_feeds:
+                        self.posts.append(post.source_path)
                         self.posts_per_year[
                             str(post.date.year)].append(post.source_path)
                         self.posts_per_month[
diff --git a/nikola/plugins/task/archive.py b/nikola/plugins/task/archive.py
--- a/nikola/plugins/task/archive.py
+++ b/nikola/plugins/task/archive.py
@@ -48,17 +48,28 @@ def gen_tasks(self):
             "output_folder": self.site.config['OUTPUT_FOLDER'],
             "filters": self.site.config['FILTERS'],
             "create_monthly_archive": self.site.config['CREATE_MONTHLY_ARCHIVE'],
+            "create_single_archive": self.site.config['CREATE_SINGLE_ARCHIVE'],
         }
         self.site.scan_posts()
         yield self.group_task()
         # TODO add next/prev links for years
+        if kw['create_monthly_archive'] and kw['create_single_archive']:
+            raise Exception('Cannot create monthly and single archives at the same time.')
         for lang in kw["translations"]:
-            for year, posts in self.site.posts_per_year.items():
+            archdata = self.site.posts_per_year
+            # A bit of a hack.
+            if kw['create_single_archive']:
+                archdata = {None: self.site.posts}
+
+            for year, posts in archdata.items():
                 output_name = os.path.join(
                     kw['output_folder'], self.site.path("archive", year, lang))
                 context = {}
                 context["lang"] = lang
-                context["title"] = kw["messages"][lang]["Posts for year %s"] % year
+                if year:
+                    context["title"] = kw["messages"][lang]["Posts for year %s"] % year
+                else:
+                    context["title"] = kw["messages"][lang]["Archive"]
                 context["permalink"] = self.site.link("archive", year, lang)
                 if not kw["create_monthly_archive"]:
                     template_name = "list_post.tmpl"
@@ -117,32 +128,33 @@ def gen_tasks(self):
                 task['basename'] = self.name
                 yield task
 
-        # And global "all your years" page
-        years = list(self.site.posts_per_year.keys())
-        years.sort(reverse=True)
-        template_name = "list.tmpl"
-        kw['years'] = years
-        for lang in kw["translations"]:
-            context = {}
-            output_name = os.path.join(
-                kw['output_folder'], self.site.path("archive", None,
-                                                    lang))
-            context["title"] = kw["messages"][lang]["Archive"]
-            context["items"] = [(year, self.site.link("archive", year, lang))
-                                for year in years]
-            context["permalink"] = self.site.link("archive", None, lang)
-            task = self.site.generic_post_list_renderer(
-                lang,
-                [],
-                output_name,
-                template_name,
-                kw['filters'],
-                context,
-            )
-            task_cfg = {1: task['uptodate'][0].config, 2: kw}
-            task['uptodate'] = [config_changed(task_cfg)]
-            task['basename'] = self.name
-            yield task
+        if not kw['create_single_archive']:
+            # And an "all your years" page for yearly and monthly archives
+            years = list(self.site.posts_per_year.keys())
+            years.sort(reverse=True)
+            template_name = "list.tmpl"
+            kw['years'] = years
+            for lang in kw["translations"]:
+                context = {}
+                output_name = os.path.join(
+                    kw['output_folder'], self.site.path("archive", None,
+                                                        lang))
+                context["title"] = kw["messages"][lang]["Archive"]
+                context["items"] = [(year, self.site.link("archive", year, lang))
+                                    for year in years]
+                context["permalink"] = self.site.link("archive", None, lang)
+                task = self.site.generic_post_list_renderer(
+                    lang,
+                    [],
+                    output_name,
+                    template_name,
+                    kw['filters'],
+                    context,
+                )
+                task_cfg = {1: task['uptodate'][0].config, 2: kw}
+                task['uptodate'] = [config_changed(task_cfg)]
+                task['basename'] = self.name
+                yield task
 
     def archive_path(self, name, lang):
         if name:


Test patch: