summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c29
-rw-r--r--templates/template.txt48
-rw-r--r--util.c39
-rw-r--r--util.h (renamed from config.h)14
4 files changed, 123 insertions, 7 deletions
diff --git a/main.c b/main.c
index f51541f..c1f1718 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
/*
* This file is part of websitegen, a website generator for https://danieljon.es
* Copyright (C) 2018 Daniel Jones daniel@danieljon.es
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -16,12 +17,38 @@
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "util.h"
#include "replace.h"
-#include "config.h"
#include "cfg.h"
+
int
main(void)
{
+ struct cfgfile *cfg = malloc(sizeof(struct cfgfile));
+ if (!cfgsetup(cfg, "settings.cfg"))
+ {
+ perror("failed to create cfg structure");
+ cfgfree(cfg);
+ exit(1);
+ }
+ char test[256];
+ cfggetvalue(cfg, "blogtitle", test, sizeof(test));
+ puts(test);
+ char val[3];
+ cfggetvalue(cfg, "postsperpage", val, sizeof(val));
+ printf("%d\n", atoi(val)*2);
+ cfgfree(cfg);
+
+ char *content = readfilecontent("templates/template.txt");
+ if (!content)
+ perror("unable to read file");
+ char *replaced = replaceinmemory(content, "{CONTENT}", "test");
+ puts(replaced);
+ free(content);
+ free(replaced);
return 0;
}
diff --git a/templates/template.txt b/templates/template.txt
new file mode 100644
index 0000000..0a9dd34
--- /dev/null
+++ b/templates/template.txt
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
+<meta name="keywords" content="Programming, C++, C, Blog">
+<meta name="description" content="Personal blog/portfolio/site for Daniel Jones">
+<meta name="author" content="Daniel Jones">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<meta http-equiv="Cache-control" content="public">
+<link rel="icon" type="image/png" href="https://danieljon.es/favicon.png">
+<title>{TITLE}</title>
+<style>
+body
+{
+ max-width: 45rem;
+ padding-left: 1rem;
+ padding-right: 1rem;
+ margin-right: auto;
+ margin-left: auto;
+ font-family: Verdana
+}
+img{max-width: 100%; max-height: 100%; overflow: hidden;}
+pre{padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; background: #d9d9ce; overflow: auto;}
+.middle{text-align: center;}
+.middiv{margin: auto; width: 80%;}
+#gentag{text-align: center; font-size: 75%;}
+h1,h2,h3,h4{padding-left: 5px;}
+div.viewing{max-width: 70%; width: 100%; display: inline-block; margin: 10px;}
+div.cover{display:inline-block; vertical-align: top; padding-top: 28px; padding-left: 15px; padding-bottom: 20px;}
+.content{border: 1px solid black; border-radius: 5px; padding-top: 15px; padding-bottom: 15px; padding-left: 15px; padding-right: 15px; background: #eeeeec;}
+</style>
+</head>
+<body>
+<div class="middle">
+<h1>danieljon.es</h1>
+<a href="https://danieljon.es">normal</a> <a href="https://solarized.danieljon.es">solarized</a> <a href="https://dark.danieljon.es">dark</a> <a href="https://nocss.danieljon.es">no css</a> <br>
+<a href="/">index</a> <a href="/blog">blog</a> <a href="/opinions">opinions</a> <a href="/interesting.html">interesting</a> <a href="https://git.danieljon.es">cgit</a> <br>
+<a href="/like.html">likes</a> <a href="/dislike.html">dislikes</a>
+{INFO}
+</div>
+<div class="content">
+{CONTENT}
+</div>
+<br><br> <div class="middle"> <img src="https://danieljon.es/linuxfreak.png"> <br> <a href="https://gitlab.com/ubunchu-translators/ubunchu">source</a> </div>
+<br> <div id="gentag">page generated {TIME} using <a href="https://git.danieljon.es/website/">sitegenerator</a></div>
+<!-- <a href="https://danieljon.es/girlslasttour"><img src="https://danieljon.es/media/chito.png" style="position: fixed; right: 0px; bottom: -0px; width: 80px; height: auto;"></a> -->
+</body>
+</html>
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..7615962
--- /dev/null
+++ b/util.c
@@ -0,0 +1,39 @@
+/*
+ * This file is part of websitegen, a website generator for https://danieljon.es
+ * Copyright (C) 2018 Daniel Jones daniel@danieljon.es
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include "util.h"
+ #include "replace.h"
+
+char *
+readfilecontent(char *file)
+{
+ /* read file and return pointer to string containing the content */
+ FILE *fp = fopen(file, "r");
+ if (!fp)
+ return NULL;
+ size_t destsize = getfilelength(fp);
+ char *dest = malloc(destsize+1);
+ if (!dest)
+ goto skipfread;
+ fread(dest, destsize, 1, fp);
+skipfread:
+ fclose(fp);
+ return dest;
+}
diff --git a/config.h b/util.h
index 19555bb..767ac38 100644
--- a/config.h
+++ b/util.h
@@ -1,6 +1,7 @@
/*
* This file is part of websitegen, a website generator for https://danieljon.es
* Copyright (C) 2018 Daniel Jones daniel@danieljon.es
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -15,9 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/* blog */
-const char *blogindir = "content/blog/";
-const char *blogoutdir = "output/blog/";
-const int postsperpage = 10;
-const char *blogtitle = "daniel's blog";
-const char *header = "<h1>Blog</h1> Rambles about programming, technology and life.<br><br>";
+#ifndef UTIL_H
+#define UTIL_H
+
+char *
+readfilecontent(char *file);
+
+#endif