FEATURE: Allow fetching top topics, and allow random selection

FEATURE: Allow fetching top topics, and allow random selection

diff --git a/javascripts/discourse/components/featured-tiles.js b/javascripts/discourse/components/featured-tiles.js
index 9430878..f39af20 100644
--- a/javascripts/discourse/components/featured-tiles.js
+++ b/javascripts/discourse/components/featured-tiles.js
@@ -10,6 +10,17 @@ const displayCategories = settings.display_categories
 
 const featuredTags = settings.featured_tags.split("|");
 
+function shuffle(array) {
+  array = [...array];
+
+  // https://stackoverflow.com/a/12646864
+  for (let i = array.length - 1; i > 0; i--) {
+    const j = Math.floor(Math.random() * (i + 1));
+    [array[i], array[j]] = [array[j], array[i]];
+  }
+
+  return array;
+}
 export default Component.extend({
   isLoading: true,
   classNameBindings: "isLoading",
@@ -35,10 +46,10 @@ export default Component.extend({
 
     this.store
       .findFiltered("topicList", {
-        filter: "latest",
-        params: loadParams,
+        filter: settings.topic_source,
+        params: loadParams
       })
-      .then((list) => {
+      .then(list => {
         this.set("list", list);
         next(this, () => this.set("isLoading", false)); // Use `next` for CSS animation
       });
@@ -47,6 +58,9 @@ export default Component.extend({
   @discourseComputed("list.topics")
   filteredTopics(topics) {
     if (!topics) return;
+    if (settings.randomize_topics) {
+      topics = shuffle(topics);
+    }
     return topics.slice(0, settings.maximum_topic_count);
   },
 
diff --git a/locales/en.yml b/locales/en.yml
index 9862cab..e58d50f 100644
--- a/locales/en.yml
+++ b/locales/en.yml
@@ -3,6 +3,8 @@ en:
     description: Display a horizontal strip of featured topics above a category
     settings:
       featured_tags: The tag which contains the featured topics. This must be publically visible.
+      topic_source: Which algorithm should be used to pick topics?
+      randomize_topics: Randomize the selection and ordering of topics?
       maximum_topic_count: The maximum number of topics to display
       display_when_unfiltered: Display on the unfiltered latest page?
       display_on_categories: Display on category pages?
diff --git a/settings.yml b/settings.yml
index fcf09d7..a95c69f 100644
--- a/settings.yml
+++ b/settings.yml
@@ -2,6 +2,18 @@ featured_tags:
   type: list
   list_type: tag
   default: "featured"
+topic_source:
+  type: enum
+  default: "top/yearly"
+  choices:
+    - latest
+    - top/all
+    - top/yearly
+    - top/quarterly
+    - top/monthly
+    - top/weekly
+    - top/daily
+randomize_topics: true
 display_when_unfiltered: true
 display_on_categories: true
 display_categories: 

GitHub sha: 4343926a09ae28af6707c91cf82436bd8aadcb4d