diff options
| -rw-r--r-- | config.h | 4 | ||||
| -rw-r--r-- | main.c | 6 | ||||
| -rw-r--r-- | pages.c | 41 | ||||
| -rw-r--r-- | pages.h | 3 | 
4 files changed, 45 insertions, 9 deletions
| @@ -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 @@ -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;  } @@ -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; +} @@ -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 | 
