This commit is contained in:
radhitya 2025-01-21 23:12:38 +07:00
parent 9e92850751
commit f0800f0c2c

17
main.c
View File

@ -108,7 +108,6 @@ void get_posts(const char *path, Post *posts, int *count) {
void generate_pagination(Post *posts, int total_posts, int posts_per_page) { void generate_pagination(Post *posts, int total_posts, int posts_per_page) {
header = doinsert("./media/header.html"); header = doinsert("./media/header.html");
footer = doinsert("./media/footer.html");
int total_pages = (total_posts + posts_per_page - 1) / posts_per_page; int total_pages = (total_posts + posts_per_page - 1) / posts_per_page;
FILE *archive = fopen("./target/archive.html", "w"); FILE *archive = fopen("./target/archive.html", "w");
@ -116,11 +115,17 @@ void generate_pagination(Post *posts, int total_posts, int posts_per_page) {
perror("Galat archive.html"); perror("Galat archive.html");
return; return;
} }
printf("%s", header);
fprintf(archive, "<html>\n<head>\n<meta charset=\"utf-8\"/>\n"); fprintf(archive, "<html>\n<head>\n<meta charset=\"utf-8\"/>\n");
fprintf(archive, "<title>Archive - %s</title>", SUBTITLE); fprintf(archive, "<title>Archive - %s</title>", SUBTITLE);
fprintf(archive, "<link rel=\"stylesheet\" href=\"style.css\">\n</head>\n"); fprintf(archive, "<link rel=\"stylesheet\" href=\"style.css\">\n</head>\n");
fprintf(archive, "<body>"); if (header != NULL) {
fprintf(archive, "%s", header);
} else {
fprintf(stderr, "ga bisa buat header wqwqwq");
}
fprintf(archive, "<body>");
fprintf(archive,"<h1>Archive</h1><ul>"); fprintf(archive,"<h1>Archive</h1><ul>");
for(int page = 0; page < total_pages; page++) { for(int page = 0; page < total_pages; page++) {
@ -137,6 +142,13 @@ void generate_pagination(Post *posts, int total_posts, int posts_per_page) {
fprintf(page_file, "<html>\n<head>\n<meta charset=\"utf-8\"/>\n"); fprintf(page_file, "<html>\n<head>\n<meta charset=\"utf-8\"/>\n");
fprintf(page_file, "<title>Page %d - %s</title>", page+1, SUBTITLE); fprintf(page_file, "<title>Page %d - %s</title>", page+1, SUBTITLE);
fprintf(page_file, "<link rel=\"stylesheet\" href=\"style.css\">\n</head>"); fprintf(page_file, "<link rel=\"stylesheet\" href=\"style.css\">\n</head>");
if (header != NULL) {
fprintf(page_file, "%s", header);
} else {
fprintf(stderr, "ga bisa buat header wqwqwq");
}
fprintf(page_file,"<h1>Page %d</h1><ul>", page + 1); fprintf(page_file,"<h1>Page %d</h1><ul>", page + 1);
int start = page * posts_per_page; int start = page * posts_per_page;
@ -148,6 +160,7 @@ void generate_pagination(Post *posts, int total_posts, int posts_per_page) {
fprintf(page_file, "<li><a href='%s'>%s</a></li>", html_name, posts[i].name); fprintf(page_file, "<li><a href='%s'>%s</a></li>", html_name, posts[i].name);
} }
fprintf(page_file, "</ul>\n<a href='archive.html'>kembali</a>"); fprintf(page_file, "</ul>\n<a href='archive.html'>kembali</a>");
footer = doinsert("./media/footer.html");
if (footer != NULL) { if (footer != NULL) {
fprintf(page_file, "%s", footer); fprintf(page_file, "%s", footer);
} else { } else {