fixed bug

This commit is contained in:
Your Name 2025-01-25 10:27:33 +03:00
parent 8f882ced2b
commit 3f54bd1a04
5 changed files with 28 additions and 32 deletions

View File

@ -4,7 +4,7 @@
Performance: Performance:
11 sec when processing a 11 sec when processing a
564kb database containing 564kb database containing
1685 rows on orange pi 4 lts (cpu freq: 816Mhz) 1685 files on orange pi 4 lts (cpu freq: 816Mhz)
And 5sec at 1.8GHz And 5sec at 1.8GHz

View File

@ -1,12 +1,12 @@
/* Absolute path to */ /* Absolute path to */
#define ROOT "." #define ROOT "8img_dir"
#define DB ROOT"/db" #define DB ROOT"/db"
/* Html generator */ /* Html generator */
#define CSS "style.css" #define CSS "style.css"
#define LOGO "logo.jpg" #define LOGO "logo.png"
#define DESC "from outer space" #define DESC "-> from outer space"
#define TITLE "8img gallery" #define TITLE "8img gallery"
#define POST_PER_PAGE 5 #define POST_PER_PAGE 5

20
img.c
View File

@ -189,7 +189,7 @@ struct DB_STR *new_db_value(char *str) {
*ptr = '\0'; *ptr = '\0';
for (size_t i = 0; i < strlen(tok); i++) for (size_t i = 0; i < strlen(tok); i++)
if (tok[i] == ',') if (tok[i] == ',' && tok[i + 1])
db->size++; db->size++;
size_t allocated = 0; size_t allocated = 0;
@ -256,14 +256,14 @@ RDB_CLOSE:
} }
struct DB_STR *build_html(FILE *fp, const char *file, const struct UNIQ_TAGS ut, struct DB_STR *db, const size_t page, const size_t pages) { struct DB_STR *build_html(FILE *fp, const char *file, const struct UNIQ_TAGS ut, struct DB_STR *db, const size_t page, const size_t pages) {
fprintf(fp, "<html>\n<head>\n<link rel='stylesheet' href='%s'>\n<title>%s</title>\n</head>\n<body>\n<a href='index.html'><img id='logo' src='%s'></a><h1 id='desc'>%s<br>%s/p%zu</h1>\n<center>", CSS, TITLE, LOGO, DESC, file, page); fprintf(fp, "<html>\n<head>\n<link rel='stylesheet' href='%s'>\n<title>%s</title>\n</head>\n<body>\n<a href='index.html'><img id='logo' src='%s'></a><h1 id='desc'>%s<br>%s/p%zu</h1>\n", CSS, TITLE, LOGO, DESC, file, page);
/* Tags */ /* Tags */
fputs("\n<a id='alltags' href='index.html'>all</a>", fp); fputs("<center><div class='alltags'>\n<a href='index.html'>all</a>", fp);
for (size_t i = 0; i < ut.size; i++) for (size_t i = 0; i < ut.size; i++)
fprintf(fp, "<a id='alltags' href='%s.html'> %s</a>", ut.tags[i], ut.tags[i]); fprintf(fp, "<a href='%s.html'> %s</a>", ut.tags[i], ut.tags[i]);
fputs("\n<br><br><br>\n", fp); fputs("\n</center></div><br><br>\n", fp);
/* Images */ /* Images */
size_t images = 0; size_t images = 0;
@ -282,9 +282,9 @@ struct DB_STR *build_html(FILE *fp, const char *file, const struct UNIQ_TAGS ut,
} }
} }
fprintf(fp, "<a href='%s'><img src='%s' alt='%s'></a><br>", p->filename, p->filename, p->filename); fprintf(fp, "<a href='%s'>\n<img src='%s' alt='%s'></a><br>\n>", p->filename, p->filename, p->filename);
for (size_t i = 0; i < p->size; i++) for (size_t i = 0; i < p->size; i++)
fprintf(fp, "<a class='tags' href='%s.html'> %s</a>", p->tags[i], p->tags[i]); fprintf(fp, "<a href='%s.html'> %s</a>", p->tags[i], p->tags[i]);
fputs("\n<br><br><br>\n", fp); fputs("\n<br><br><br>\n", fp);
@ -294,7 +294,7 @@ struct DB_STR *build_html(FILE *fp, const char *file, const struct UNIQ_TAGS ut,
break; break;
} }
fputs("\n<div class='pager'>\n", fp); fputs("<div class='pager'><center>\n", fp);
for (size_t i = 0; i <= pages; i++) { for (size_t i = 0; i <= pages; i++) {
if (i == 0) { if (i == 0) {
if (i == page) if (i == page)
@ -317,7 +317,7 @@ struct DB_STR *build_html(FILE *fp, const char *file, const struct UNIQ_TAGS ut,
} }
fprintf(fp, "\n</div>\n</center>\n</body>\n</html>\n"); fprintf(fp, "\n</center></div>\n</body>\n</html>\n");
return p; return p;
} }
@ -331,7 +331,7 @@ void build(const char *file, const struct UNIQ_TAGS ut, struct DB_STR *db) {
while (p != NULL) { while (p != NULL) {
struct DB_STR *i = p->next; struct DB_STR *i = p->next;
if (count == POST_PER_PAGE) { if (count > POST_PER_PAGE) {
count = 0; count = 0;
pages++; pages++;
} }

BIN
logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 784 B

View File

@ -1,36 +1,32 @@
/* Global */
body { body {
word-break: break-word;
margin: auto; margin: auto;
padding: 2em; padding: 2em;
background-color: #1d2021;
color: #928374;
} }
a { a {
text-decoration: none; text-decoration: none;
color: #000000; color: #ebdbb2;
}
/* */
#logo {
display: block;
max-width: 10%;
} }
#desc { /* Tags */
color: #000000; .alltags {
background-color: #ebdbb2;
} }
.tags { .alltags a {
color: #000000; color: #1d2021;
} }
/* */
.pager {}
.pager a { /* Pager */
.pager #curr {
text-decoration: underline; text-decoration: underline;
} }
.pager #curr {
color: #ffffff;
background-color: #000000;
}