summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h4
-rw-r--r--main.c6
-rw-r--r--pages.c41
-rw-r--r--pages.h3
4 files changed, 45 insertions, 9 deletions
diff --git a/config.h b/config.h
index 9f40ef3..cca7d3b 100644
--- a/config.h
+++ b/config.h
@@ -94,6 +94,9 @@ static const char *direct_output_dir = "posts/direct/";
static const int posts_per_page = 10;
static const int ignore[] = {}; /* ignore these posts */
+/* rss */
+static const char *rss_output = "posts/posts.rss";
+
/* each page to be generated go into this array */
static const struct page pages[] = {
/* function flags */
@@ -106,6 +109,7 @@ static const struct page pages[] = {
{opinions_everythingpage, NONE},
{portfoliopage, NONE},
{postspage, NONE},
+ {rsspage, NONE},
};
#endif
diff --git a/main.c b/main.c
index ae1b945..7e4955b 100644
--- a/main.c
+++ b/main.c
@@ -22,7 +22,11 @@ main(void)
{
for (size_t i = 0; i < sizeof(pages)/sizeof(pages[0]); i++)
{
- pages[i].function(pages[i].flags);
+ if (!pages[i].function(pages[i].flags))
+ {
+ fprintf(stderr, "error generating website\n");
+ return 1;
+ }
}
return 0;
}
diff --git a/pages.c b/pages.c
index 51509cf..f0b2eb4 100644
--- a/pages.c
+++ b/pages.c
@@ -25,15 +25,27 @@ makedirectories(const char *basedir, const char *file)
*/
// TODO: implement
char buffer[512];
+ struct stat sb = {0};
+
+ if(!stat(output_dir, &sb) == 0 && !S_ISDIR(sb.st_mode))
+ {
+ fprintf(stderr, "directory '%s' does not exist, trying to make directory..\n", output_dir);
+ if (mkdir(output_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+ {
+ fprintf(stderr, "unable to mkdir '%s', unrecoverable failure\n", output_dir);
+ return 0;
+ }
+ fprintf(stderr, "OK\n");
+ }
return 1;
}
int
-createfile(const char *file)
+createfile(const char *file, const char *template)
{
/*
- * create file at location 'output_dir'/file' using the template
+ * create file at location 'output_dir'/file' using the template 'template'
* overwrite if it exists
* assume the caller has put us in the base directory already
*/
@@ -42,7 +54,12 @@ createfile(const char *file)
* FIXME: if trying to create a file with subdirectories it will not work
* one day tokenise the file path and make them
*/
+ if (!makedirectories(output_dir, file))
+ {
+ fprintf(stderr, "unable to create directories for '%s/%s', unrecoverable failure\n", output_dir, file);
+ return 0;
+ }
struct stat sb = {0};
if(!stat(output_dir, &sb) == 0 && !S_ISDIR(sb.st_mode))
@@ -66,7 +83,7 @@ createfile(const char *file)
return 0;
}
- FILE *in = fopen(template_file, "r");
+ FILE *in = fopen(template, "r");
if (!in)
{
fprintf(stderr, "Error opening file: %s\n", strerror(errno));
@@ -378,9 +395,9 @@ createtmpfile(const char *name, const char *content, size_t size)
int
genericpage(int flags, const char *output, const char *ind, const char *tit, const char *inf)
{
- if (!createfile(output))
+ if (!createfile(output, template_file))
{
- fprintf(stderr, "unable to generate frontpage\n");
+ fprintf(stderr, "unable to generate genericpage\n");
return 0;
}
@@ -477,7 +494,7 @@ createdirectpages(const int *posts, size_t totalposts)
/* source file */
snprintf(source, 512, "%s%d.txt", posts_content, posts[x]);
- if (!createfile(file))
+ if (!createfile(file, template_file))
{
fprintf(stderr, "unable to create file '%s', unrecoverable failure\n", file);
return 0;
@@ -617,7 +634,7 @@ generatepostpages(const int *posts, size_t totalposts, int pagecount)
{
/* loop through and create every post page required */
snprintf(outfilename, 512, "%s%d.html", posts_output_dir, i);
- if (!createfile(outfilename))
+ if (!createfile(outfilename, template_file))
{
fprintf(stderr, "unable to create file '%s', unrecoverable failure\n", outfilename);
return 0;
@@ -701,3 +718,13 @@ postspage(int flags)
}
return 1;
}
+
+/* rss */
+int
+rsspage(int flags)
+{
+ /*
+ * generate an rss feed for our blog/posts
+ */
+ return 1;
+}
diff --git a/pages.h b/pages.h
index 936a11e..7639e4f 100644
--- a/pages.h
+++ b/pages.h
@@ -32,7 +32,7 @@ struct fileorstring
};
/* helpers */
-int createfile(const char *file);
+int createfile(const char *file, const char *template);
long findstring(const char *file, const char *str);
int deletebytes(const char *file, long offset, size_t bytes);
int writeatbyte(const char *dest, struct fileorstring *source, long offset);
@@ -57,5 +57,6 @@ int opinions_animepage(int flags);
int opinions_everythingpage(int flags);
int portfoliopage(int flags);
int postspage(int flags);
+int rsspage(int flags);
#endif