diff options
| author | Inqiyad Sabr <sabr@ariamath.xyz> | 2025-11-02 10:07:40 +0600 |
|---|---|---|
| committer | Inqiyad Sabr <sabr@ariamath.xyz> | 2025-11-02 10:07:40 +0600 |
| commit | 11b86ff1a85efe5d1170ea8c90ebca5ac313e24f (patch) | |
| tree | 12356d8e8677d77b166b8e00d614f491d632597b | |
Add files
| -rw-r--r-- | Makefile | 33 | ||||
| -rw-r--r-- | README.md | 25 | ||||
| -rwxr-xr-x | c2x | 8 | ||||
| -rw-r--r-- | g2x.c | 68 |
4 files changed, 134 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4f2f0c0 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +.POSIX: + +RM := /bin/rm +DESTDIR := /usr/local/bin + +CFLAGS := -std=c99 -Wfloat-equal -Og +CFLAGS += -Wall -Werror -Wextra -Wpedantic +CFLAGS += -m64 -no-pie -pipe +CFLAGS += -ffunction-sections -fdata-sections +CFLAGS += -D_XOPEN_SOURCE=500L -flto +CFLAGS += -march=native -mtune=generic + +LDFLAGS := -static -Wl,--build-id=none +LDFLAGS += -ffunction-sections -fdata-sections +#LDFLAGS += -Wl,--strip-all +LDFLAGS += -Wl,--flto + +.SUFFIXES: .c .o + +g2x: $(FILES) *.o + $(CC) $(LDFLAGS) *.o -o g2x + +.c.o: + $(CC) $(CFLAGS) -c *.c + +clean: + $(RM) ./*.o + +install: + install -s -m 0755 g2x $(DESTDIR) + install -m 0755 c2x $(DESTDIR) + +.PHONY: make clean install diff --git a/README.md b/README.md new file mode 100644 index 0000000..b5838a1 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Gemini To XHTML(XML) +This is a very simple gemini to xml generator written in C. + +# About +The g2x executable is a single file to file xml generator, there's a handy script named c2x (capsule 2 xhtml), that generates the entire capsule in XHTML for you, then you can use your favourite web server to host it. + +# Usage +You use your shell pipes '>' and '<'. + +* generate one html from gmi file +``` +./g2h < index.gmi > index.html +``` + +* Generate a whole ass mfkin gemsite +``` +./c2x <gemsite_root> +``` + +without the "/"... btw. + +That's it, just add your style.css at the *_xhtml root and you got XHTML! HELL YEAH! Hhhmm... I mean HTML is kinda messed up and you should always just use XHTML. + +# Addenum +I thought I might add how I work. I have my gemsite as a git repo where I have a post-receive hook that copies my gemsite to a gemsite folder, and then it runs `c2x` on the gemsite root folder and I get a `gemsite_xhtml` folder, being the XHTML root. Then I just nginx and you know the deal. @@ -0,0 +1,8 @@ +#!/bin/sh +[ -s ./"$1_xhtml" ] && rm -rf "./${1}_xhtml" +cp -r ./"${1}" ./"${1}_xhtml" +cd ./"${1}_xhtml" || exit +for file in $(find ./* | grep ".gmi" | sed 's/.gmi//'); do + g2x < "./${file}.gmi" > "./${file}.html" + rm "./${file}.gmi" +done @@ -0,0 +1,68 @@ +#include <stdio.h> +#define BUFSIZE 4096 // Read +#define xmlput(n)\ + for(i = n; buf[i] != '\n'; i++) {\ + switch(buf[i]) {\ + default: putchar(buf[i]); break;\ + case '>' : fputs(">",stdout); break;\ + case '<' : fputs("<",stdout); break;\ + case '&' : fputs("&",stdout); break;\ + case '\'': fputs("'",stdout); break;\ + case '"' : fputs(""",stdout); break;}} +int main(void) { + char buf[BUFSIZE]; int i; + fputs( + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE html PUBLIC ""\"-//W3C//DTD XHTML " + "1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/" + "DTD/xhtml1-strict.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\" " + "xml:lang=\"en\" lang=\"en\">\n<head>\n" + "<meta name=\"viewport\" " + "content=\"width=device-width, " + "initial-scale=1\" />\n" + "<link rel=\"stylesheet\" " + "type=\"text/css\" href=\"/style.css\" />\n" + "<title></title></head><body>",stdout + ); while (fgets(buf,BUFSIZE,stdin) != NULL) { + if (buf[2] == '#')/* ### */ { + fputs("<h3>",stdout); + xmlput(4); fputs("</h3>\n",stdout); + continue; + } else if (buf[1] == '#') /* ## */ { + fputs("<h2>",stdout); + xmlput(3); fputs("</h2>\n",stdout); + continue; + } else if (buf[0] == '#') /* # */ { + fputs("<h1>",stdout); + xmlput(2); fputs("</h1>\n",stdout); + continue; + } else if (buf[0] == '*') { + fputs("<ul><li>",stdout); xmlput(2); + fputs("</li></ul>\n",stdout); continue; + } else if (buf[0] == '=' && buf[1] == '>')/* link */ { + fputs("<p><a href=\"",stdout); + for (i = 3; buf[i] != '.' && buf[i] != ' '; i++) + putchar(buf[i]); + if (buf[i+1] == 'g') {fputs(".html",stdout);i=i+3;} + else {for (;buf[i] != ' '; i++) putchar(buf[i]);} + fputs("\">",stdout); xmlput(i+1); + fputs("</a></p>\n",stdout); + continue; + } else if (buf[0] == '`' && buf[2] == '`')/* code */ { + fputs("<pre><code>",stdout); + fgets(buf,BUFSIZE,stdin); + while (buf[0] != '`' && buf[2] != '`') { + xmlput(0); fputs("\n",stdout); + fgets(buf,BUFSIZE,stdin); + } fputs("</code></pre>",stdout); + continue; + } else if (buf[0] == '>') { + fputs("<blockquote>",stdout); xmlput(2); + fputs("</blockquote>\n",stdout); + continue; + } fputs("<p>",stdout); + xmlput(0); fputs("</p>\n",stdout); + } fputs("</body>",stdout); + fputs("</html>",stdout); +} |