#include "index.h"
+static gchar
+*render_dir (Commons *commons, const gchar *dir)
+{
+ g_autoptr (GError) error = NULL;
+ g_autoptr (GFile) gfdir = NULL;
+ g_autoptr (GFileEnumerator) gfenum = NULL;
+
+ g_autoptr (GString) ret;
+
+ g_autofree gchar *path;
+
+ path = g_build_filename (commons->root, dir, NULL);
+
+ ret = g_string_new ("");
+ g_string_append_printf (ret, "<h1>%s</h1>\n", path);
+ g_string_append (ret, "<ul>\n");
+
+ gfdir = g_file_new_for_path (path);
+ if (g_file_query_file_type (gfdir, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY)
+ {
+ error = NULL;
+ gfenum = g_file_enumerate_children (gfdir, NULL, G_FILE_QUERY_INFO_NONE, NULL, &error);
+ if (gfenum == NULL)
+ {
+ g_warning ("Error on directory enumeration: %s", error->message);
+ return "";
+ }
+
+ while (TRUE)
+ {
+ g_autoptr (GFile) gf = NULL;
+ g_autoptr (GFileInfo) gfi = NULL;
+
+ error = NULL;
+ if (!g_file_enumerator_iterate (gfenum, &gfi, &gf, NULL, &error))
+ {
+ g_warning ("Error on reading file: %s", error->message);
+ continue;
+ }
+ if (gf == NULL)
+ {
+ break;
+ }
+
+ GFileType gft;
+
+ gft = g_file_info_get_file_type (gfi);
+ if (gft == G_FILE_TYPE_DIRECTORY
+ || gft == G_FILE_TYPE_REGULAR)
+ {
+ g_string_append_printf (ret, "<li>%s</li>\n", g_file_get_basename (gf));
+ }
+ }
+ }
+
+ g_string_append (ret, "</ul>\n");
+
+ return g_strdup (ret->str);
+}
+
void
index_index (GMatchInfo *minfo, gpointer user_data)
{
g_autoptr(GError) error = NULL;
TmplSymbol *symbol = NULL;
gchar *str;
- g_warning ("INDEX INDEX");
+
+ gchar *dir;
+
Commons *commons = (Commons *)user_data;
file = g_file_new_for_path (CTPLDIR "/template.ctpl");
tmpl_symbol_assign_string (symbol, "");
symbol = tmpl_scope_get (scope, "body");
- tmpl_symbol_assign_string (symbol, commons->root);
+ dir = render_dir (commons, "/");
+ tmpl_symbol_assign_string (symbol, dir);
symbol = tmpl_scope_get (scope, "body_tag");
tmpl_symbol_assign_string (symbol, "");