add some ecommerce stuff and uh remove my deadname from the actual code

This commit is contained in:
Iris Lightshard 2024-10-06 17:58:48 -06:00
parent 2bf39ebcff
commit 7b0a9ce79a
Signed by: Iris Lightshard
GPG key ID: 688407174966CAF3
2 changed files with 149 additions and 14 deletions

View file

@ -18,4 +18,5 @@
#define ABOUT_HTML "<h2>Welcome to this website</h2>" #define ABOUT_HTML "<h2>Welcome to this website</h2>"
#define NAME "a website" #define NAME "a website"
#define IS_HTML5_VIDEO_ENABLED 0 #define IS_HTML5_VIDEO_ENABLED 0
#define CONTACT_ADDRESS "contact@amotherfuckingwebsite.com"
/* clang-format on */ /* clang-format on */

162
main.c
View file

@ -9,7 +9,7 @@
#include "config.h" #include "config.h"
/* /*
Copyright (c) 2021 Derek Stevens Copyright (c) 2021 Iris Lightshard
Copyright (c) 2021 Devine Lu Linvega Copyright (c) 2021 Devine Lu Linvega
Permission to use, copy, modify, and distribute this software for any Permission to use, copy, modify, and distribute this software for any
@ -54,6 +54,12 @@ int error(char* msg, char* val) {
return 0; return 0;
} }
void clearstr(char* s) {
while (*s) {
*s++ = 0;
}
}
time_t getlater(time_t a, time_t b) { return a > b ? a : b; } time_t getlater(time_t a, time_t b) { return a > b ? a : b; }
int ismetanav(char* name) { return scmp(name, "meta.nav"); } int ismetanav(char* name) { return scmp(name, "meta.nav"); }
@ -75,7 +81,7 @@ int gettwtxt(FILE* f) {
char datebuf[16] = {0}; char datebuf[16] = {0};
char msgbuf[240] = {0}; char msgbuf[240] = {0};
char urlbuf[256] = {0}; char urlbuf[256] = {0};
char *l, *d, *m, *u; char* l;
FILE* twtxt = fopen(SITEROOT TWTXT, "r"); FILE* twtxt = fopen(SITEROOT TWTXT, "r");
scat(buf, "<div id='twtxtFeed'><h2>recent activity</h2>\n<table>\n"); scat(buf, "<div id='twtxtFeed'><h2>recent activity</h2>\n<table>\n");
@ -121,18 +127,9 @@ int gettwtxt(FILE* f) {
scat(buf, msgbuf); scat(buf, msgbuf);
} }
scat(buf, "</td></tr>\n"); scat(buf, "</td></tr>\n");
d = datebuf; clearstr(datebuf);
while (*d) { clearstr(msgbuf);
*d++ = 0; clearstr(urlbuf);
}
m = msgbuf;
while (*m) {
*m++ = 0;
}
u = urlbuf;
while (*u) {
*u++ = 0;
}
i++; i++;
} }
fclose(twtxt); fclose(twtxt);
@ -539,6 +536,139 @@ int fpblock(FILE* f, char* s) {
return 1; return 1;
} }
int fppiclisting(FILE* f, Lexicon* l, char* s) {
char desc[1024] = {0};
char href[1024] = {0};
char img[1024] = {0};
char metaimg[1024] = {0};
int target = 0;
char* c = s;
int i = 0;
while (i < 2) {
if (*c == '|' || !(*c)) {
i++;
c++;
continue;
}
switch (i) {
case 0:
ccat(desc, *c++);
break;
case 1:
ccat(img, *c++);
break;
}
}
scpy(desc, href, slen(desc) + 1);
scsw(stlc(href), ' ', '_');
scat(metaimg, href);
scat(metaimg, "|/");
scat(metaimg, href);
scat(metaimg, ".html|");
scat(metaimg, img);
scat(metaimg, desc);
fputs("<li>", f);
fphimg(f, metaimg);
target = findf(l, desc);
if (target < 0) {
return error("Missing link", s);
}
fprintf(f, "<a href='/%s.html' class='local'>", scsw(stlc(desc), ' ', '_'));
fprintf(f, "%s</a>", scsw(stlc(desc), '_', ' '));
l->refs[target]++;
fputs("</li>", f);
return 1;
}
int fpshop(FILE* f, Lexicon* l, char* s) {
char paylink[1024] = {0};
char desc[1024] = {0};
char img[1024] = {0};
char alt[1024] = {0};
char metaimg[1024] = {0};
char imgcountbuf[12] = {0};
int imgcount = 0;
char* c = s;
int i = 0;
while (i < 2) {
if (*c == '|' || !(*c)) {
i++;
c++;
continue;
}
switch (i) {
case 0:
ccat(paylink, *c++);
break;
case 1:
ccat(desc, *c++);
break;
}
}
fputs("<div class='product'><div class='product-imgs'>", f);
for (;;) {
if (*c == '|' || !(*c)) {
if (i % 2 == 0) {
clearstr(metaimg);
sprintf(imgcountbuf, "%d", ++imgcount);
scat(metaimg, "img");
scat(metaimg, imgcountbuf);
scat(metaimg, "|");
scat(metaimg, img);
scat(metaimg, "|");
} else {
scat(metaimg, alt);
fpimg(f, metaimg);
clearstr(imgcountbuf);
clearstr(img);
clearstr(alt);
}
if (!(*c)) {
if (i % 2 == 0) {
return error("Needs even number of args", s);
} else {
break;
}
}
i++;
c++;
continue;
}
if (i % 2 == 0) {
ccat(img, *c++);
} else {
ccat(alt, *c++);
}
}
fputs("</div>", f);
fppara(f, l, desc);
fprintf(
f,
"<div class='cta'><a href='%s'>purchase</a><a href='mailto:" CONTACT_ADDRESS
"'>inquire</a></div>",
paylink);
fputs("</div>", f);
return 1;
}
int fptemplate(FILE* f, Lexicon* l, char* s) { int fptemplate(FILE* f, Lexicon* l, char* s) {
int target = 0; int target = 0;
switch (s[0]) { switch (s[0]) {
@ -594,6 +724,10 @@ int fptemplate(FILE* f, Lexicon* l, char* s) {
return fpsans(f, l, s + 1); return fpsans(f, l, s + 1);
case ')': case ')':
return fpserif(f, l, s + 1); return fpserif(f, l, s + 1);
case '%':
return fppiclisting(f, l, s + 1);
case '^':
return fpshop(f, l, s + 1);
} }
if (s[0]) { if (s[0]) {
target = findf(l, s); target = findf(l, s);