Upgraded article title functionalify

This commit is contained in:
Dmitriy Shishkov 2020-07-05 20:15:51 +05:00
parent 55f5ccfdf4
commit fd6007b22b
9 changed files with 23 additions and 4 deletions

View File

@ -11,5 +11,6 @@ char *concat_to_front(char **str1, char *str2);
char *get_status_message(int status_code);
char *to_lower(char *str);
char *trim(char *str);
char *repair_spaces(char *str);
#endif

View File

@ -2,7 +2,7 @@
int list_articles(article_info **articles)
{
FILE *file = fopen("./static/articles_list.db", "r");
FILE *file = fopen("./static/articles/list.db", "r");
if (file == NULL)
{
perror("Couldn't open db file");

View File

@ -1,5 +1,6 @@
#include "../../include/articles_op/html.h"
#include "../../include/articles_op/article.h"
#include "../../include/utils_op/utils.h"
int gen_html_article(article_info article, char **out)
{
@ -25,6 +26,8 @@ int gen_html_article(article_info article, char **out)
process_md(article, &content);
article.title = repair_spaces(article.title);
int line_length = snprintf(NULL, 0, template_str, article.title, article.title, content) + 1;
*out = malloc(line_length);
if (*out == NULL)
@ -53,6 +56,8 @@ int gen_html_article_list(article_info *articles, int n, char **out)
for (int i = 0; i < n; i++)
{
articles[i].title = repair_spaces(articles[i].title);
int line_length = snprintf(NULL, 0, "<li><a href=\"/article/%d\" >%s</a></li>\n", i, articles[i].title) + 1;
insert = malloc(line_length);

View File

@ -85,4 +85,17 @@ char *trim(char *str)
}
return str;
}
}
char *repair_spaces(char *str)
{
for (int i = 0; i < strlen(str); i++)
{
if (str[i] == '_')
{
str[i] = ' ';
}
}
return str;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

View File

@ -1,7 +1,7 @@
# My first article on this site
This is my own site written in pure C with templates in html and some css styles. All articles are stored in markdown format and are processed by server to convert them to html and send to client. Links list on the homepage is also generated dynamically to show all the articles, currntly avaliable on disk.
![Data flow](https://c.imge.to/2020/07/03/P5RIaj.png)
![Data flow](/articles/My_first_article_on_this_site/P5RIaj.png)
*Data flow*
As for all the pages of this site are pure html, it can be read from really old computers or text-based browsers. Server Side Rendered (SSR) webpages are also good for search engines.

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

1
static/articles/list.db Normal file
View File

@ -0,0 +1 @@
1593768639 My_first_article_on_this_site

View File

@ -1 +0,0 @@
1593768639 First article