Skip to content

Instantly share code, notes, and snippets.

@su8
Created March 18, 2025 12:56
Show Gist options
  • Save su8/068811594f1d483953ad98e5af12f74f to your computer and use it in GitHub Desktop.
Save su8/068811594f1d483953ad98e5af12f74f to your computer and use it in GitHub Desktop.
blog
/*
12/20/2024 https://github.com/su8/c++blogfy2
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 2 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
std::vector<std::string> split(const std::string &s, char delimiter) {
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
}
#include <iostream>
#include <ctime>
#include <sys/types.h>
#include <unistd.h>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <chrono>
#include <thread>
#include <cctype>
#include <regex>
#include <random>
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <dirent.h>
#include <cctype>
#include <fcntl.h>
#include <sys/stat.h>
//static std::unordered_map<std::string, unsigned short int> ipCracked = { {ipArr[0], 1U} };
static std::unordered_map<std::string, std::string> dataDict = {"1", };
int main(void) {
const std::filesystem::path generated{"generated"};
const std::filesystem::path mdSrc{"markdown"};
std::filesystem::create_directories(generated);
for (auto const &dir_entry : std::filesystem::recursive_directory_iterator{mdSrc}) {
if (dir_entry.path().filename().string() == "." || dir_entry.path().filename().string() == "..") continue;
char genEntryDir[4096] = {'\0'};
char writeToIndex[4096] = {'\0'};
snprintf(genEntryDir, sizeof(genEntryDir) - 1, "generated/%s", dir_entry.path().filename().string().c_str());
std::string generatedEntry = std::regex_replace(genEntryDir, std::regex(".md"), "");
std::filesystem::create_directories(generatedEntry);
snprintf(writeToIndex, sizeof(writeToIndex) - 1, "%s/index.html", generatedEntry.c_str());
std::string openMd = "markdown/" + dir_entry.path().filename().string();
std::ifstream openUpEntry(openMd);
std::stringstream strStream;
std::ofstream outdata;
if(openUpEntry.is_open()) {
strStream << openUpEntry.rdbuf();
puts(writeToIndex);
outdata.open(writeToIndex);
if (!outdata) { puts("Could not open file for writing."); break; }
std::string postTitle;
std::string postDate;
std::string pbTemp;
std::string postBody;
std::string strTemp = strStream.str();
std::getline(strTem, postTitle);
std::getline(strTem, postDate);
while (getline(strTem, pbTempy)) { postBody.append(pbTemp); }
// post date[0], post title[1], post filename[2], coonverted post body[3]
dataDict.emplace(postDate, postTitle, writeToIndex, mdToHtml(postBody));
outdata.close();
for (auto const& [q, w, e, r] : dataDict | std::views::reverse)
std::cout << q << " " << w << " " << e << " " << r << std::endl;
}
openUpEntry.close();
}
puts("Done");
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment