Format RSS items as HTML files

This commit is contained in:
dogeystamp 2021-08-11 17:22:07 -04:00
parent 9719fbf303
commit 432fcf4308
No known key found for this signature in database
GPG Key ID: 4B11A996ADE99001
2 changed files with 11 additions and 4 deletions

View File

@ -34,3 +34,6 @@ static const int logLevel = 3;
// Set the maximum amount of redirects curl will follow.
// Use 0 to disable redirects, and -1 for no limit.
static const int maxRedirs = 10;
// File extension used for each article.
static const char fileExt[] = ".html";

View File

@ -22,7 +22,9 @@ itemAction(itemStruct *item, const char *folder)
if (fileName[0])
filePath = ecalloc(
strlen(folder) + strlen(fileName) + 2,
strlen(folder)
+ strlen(fileName) + 2
+ strlen(fileExt),
sizeof(char));
else {
logMsg(1, "Invalid article title.\n");
@ -42,6 +44,8 @@ itemAction(itemStruct *item, const char *folder)
strcat(filePath, fileName);
free(fileName);
strcat(filePath, fileExt);
FILE *itemFile = fopen(filePath, "a");
free(filePath);
@ -49,9 +53,9 @@ itemAction(itemStruct *item, const char *folder)
if (!ftell(itemFile)) {
newItems++;
fprintf(itemFile, "%s\n\n", cur->title);
fprintf(itemFile, "%s\n", san(cur->description, 0));
fprintf(itemFile, "%s\n", san(cur->link, 0));
fprintf(itemFile, "<h1>%s</h1><br>\n", cur->title);
fprintf(itemFile, "<a href=\"%s\">Link</a><br>\n", san(cur->link, 0));
fprintf(itemFile, "%s", san(cur->description, 0));
}
fclose(itemFile);