Merge branch 'master' into dev

This commit is contained in:
luca0N! 2023-12-01 08:12:03 -03:00
commit 2cc0fa67c5
Signed by: luca0N
GPG Key ID: 5978D960572B449E
3 changed files with 21 additions and 67 deletions

View File

@ -1,8 +1,8 @@
# Static Website Generator
Static Website Generator (swg) is a utility currently under development that
does exactly what's written on the tin. This utility aims to be a simple yet
painless program to automate the boring work of static website development.
Static Website Generator (swg) is a lightweight utility that does exactly
what's written on the tin. This utility aims to be a simple yet painless
program to automate the boring work of static website development.
This utility was created originally for the [development of version 3 of the
luca0N! website](https://git.luca0n.com/luca0N/luca0N-website).
@ -12,7 +12,7 @@ is discouraged. Expect bugs and bad unoptimized performance.
## License and copyright notice
Copyright © 2022-2023 luca0N!
Copyright © 20222023 luca0N!
This is free software. You are allowed to modify, redistribute and distribute
modified versions of this software under the terms of the GNU Lesser General

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 luca0N!
* Copyright (C) 2022-2023 luca0N!
*
* This file is part of Static Website Generator (swg).
*
@ -22,6 +22,7 @@
#include "Common.hxx"
#include <iostream>
#include <fstream>
const char* HR_MONTH[] = {
"January",
@ -72,25 +73,22 @@ bool is_special_file(std::string const &filename) {
}
std::string get_template(std::string const &path) {
std::string filePath = path;
// Template lookup
std::string stPath = path;
stPath += "/__swg_template.html";
FILE *swgTemplate = fopen(stPath.c_str(), "r");
if (swgTemplate == NULL) {
std::cerr << "error: couldn't open the SWG HTML template file; does it exist?\n";
perror(stPath.c_str());
filePath += "/__swg_template.html";
if (!std::filesystem::exists(filePath)) {
std::cerr << "error: couldn't find the SWG HTML template file.\n";
exit(RETURN_FAILED_INVALID_DIRECTORY);
}
// Check for content placeholder
int buflen = 8;
char buf[buflen];
std::string htmlTemplate;
while (fgets(buf, buflen, swgTemplate) != NULL) {
htmlTemplate += buf;
std::ifstream swgTemplate(filePath);
for (std::string line; std::getline(swgTemplate, line);) {
htmlTemplate += line;
if (!swgTemplate.eof())
htmlTemplate += '\n';
}
fclose(swgTemplate);
if (verbose) std::cout << "Loaded HTML template into memory.\n";
return htmlTemplate;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 luca0N!
* Copyright (C) 2022-2023 luca0N!
*
* This file is part of Static Website Generator (swg).
*
@ -22,66 +22,22 @@
#include "ConfigUtils.hxx"
#include <iostream>
#include <fstream>
#include <cstring>
#include <cassert>
#include "Common.hxx"
void parse_config(SwgContext *ctx, std::string const &path) {
std::string ctxCfgPath = path;
ctxCfgPath += "/swg.cfg";
FILE *ctxCfgFile = fopen(ctxCfgPath.c_str(), "r");
if (ctxCfgFile == NULL) {
std::cerr << "error: cannot open swg.cfg file, are you sure "
<< path << " is a valid SWG directory?" << std::endl;
perror(ctxCfgPath.c_str());
exit(RETURN_FAILED_INVALID_DIRECTORY);
}
int buflen = 16;
char cbuf[buflen];
// Yes, this looks ugly, but it works for now. Will probably optimize
// this in the future :)
//
// TODO: Optimize config file interpretation
std::list<std::string> lines = { "" };
while (fgets(cbuf, buflen, ctxCfgFile) != NULL) {
int eol = -1;
for (int c = 0; c < buflen; c++) {
if (cbuf[c] == '\0') {
break;
} else if (cbuf[c] == '\n') {
eol = c;
break;
}
}
if (eol > -1) {
cbuf[eol] = '\0';
*(--lines.end()) += cbuf;
lines.insert(lines.end(), "");
} else
*(--lines.end()) += cbuf;
}
fclose(ctxCfgFile);
std::cout << "Done loading configuration file in memory" << std::endl;
// Parse configuration file
enum ConfigNamespace { General, Blogs };
ConfigNamespace ns;
int blogCount = 0;
Blog *currentBlog = NULL; // (Blog*) malloc(sizeof(Blog));
Blog *currentBlog = NULL;
// currentBlog->name = "asd";
for (std::string line : lines) {
std::ifstream cfgStream(path);
// Parse configuration file
for (std::string line; std::getline(cfgStream, line);) {
// Skip comment lines
if (line.c_str()[0] == '#')
continue;