This commit is contained in:
Your Name 2024-11-10 20:22:33 +03:00
parent b5b7acb88f
commit 6b6884ddfa
4 changed files with 33 additions and 12 deletions

View File

@ -1,7 +1,11 @@
/* Absolute path to */
#define ROOT "8img_dir"
#define DB ROOT"/db"
/* Html generator */
#define CSS "style.css"
#define LOGO "logo.png"
#define DESC "+100500 photos of windowmaker"
#define TITLE "8img gallery" #define TITLE "8img gallery"
#define POST_PER_PAGE 5 #define POST_PER_PAGE 5
/* Absolute path to */
#define ROOT "."
#define DB ROOT"/db"
#define CSS ROOT"/style.css"

29
img.c
View File

@ -21,14 +21,23 @@ struct UNIQ_TAGS {
size_t size; size_t size;
}; };
char *gen_id(void) { char *gen_id(const char *filename) {
char *alf = "qwertyUIOPasdfghjklQWERTASDFGHJKLZXCVBNMzxcvbnm1234567890"; const char *alf = "qwertyUIOPasdfghjklQWERTASDFGHJKLZXCVBNMzxcvbnm1234567890";
static char id[6]; char *ext = strrchr(filename, '.');
for (size_t i = 0; i < sizeof(id); i++) if (ext == NULL)
ext = "";
size_t size = 7 + strlen(ext);
char *id = malloc(size);
if (id == NULL)
return NULL;
for (size_t i = 0; i < size - strlen(ext); i++)
id[i] = alf[rand() % sizeof(alf)]; id[i] = alf[rand() % sizeof(alf)];
id[sizeof(id) - 1] = '\0'; strcat(id, ext);
id[size] = '\0';
return id; return id;
} }
@ -67,8 +76,14 @@ void add(char **list, const int size) {
char new_path[PATH_MAX + 1]; char new_path[PATH_MAX + 1];
while (1) { while (1) {
name = gen_id(); name = gen_id(list[0]);
if (name == NULL) {
fprintf(stderr, "8img: malloc: %s\n", strerror(errno));
exit(1);
}
snprintf(new_path, sizeof(new_path), "%s/%s", ROOT, name); snprintf(new_path, sizeof(new_path), "%s/%s", ROOT, name);
free(name);
struct stat sb; struct stat sb;
if (stat(new_path, &sb) < 0) if (stat(new_path, &sb) < 0)
@ -239,7 +254,7 @@ 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<center>", CSS, TITLE); fprintf(fp, "<html>\n<head>\n<link rel='stylesheet' href='%s'>\n<title>%s</title>\n</head>\n<body>\n<center><a href='index.html'><img id='logo' src='%s'></a><h1 id='text'>%s</h1></center><h1 id='text'>Page %zu</h1><center>", CSS, TITLE, LOGO, DESC, page);
/* Tags */ /* Tags */
fputs("\n<a id='alltags' href='index.html'> [all] </a>", fp); fputs("\n<a id='alltags' href='index.html'> [all] </a>", fp);

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -12,6 +12,8 @@ a { text-decoration: none; }
background-color: #ebdbb2; background-color: #ebdbb2;
} }
#text { color: #ebdbb2; }
img { img {
height: auto; height: auto;
width: auto; width: auto;