Start work on HTML generator.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
tastytea 2020-07-02 08:09:58 +02:00
parent b91cba19d8
commit 20666bdf35
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 139 additions and 0 deletions

View File

@ -43,6 +43,7 @@ pkg_check_modules(libgit2 REQUIRED IMPORTED_TARGET libgit2)
find_package(CURL 7.56 REQUIRED)
add_subdirectory(src)
add_subdirectory(src/generators)
if(WITH_TESTS)
add_subdirectory(tests)

View File

@ -0,0 +1,10 @@
include(GNUInstallDirs)
add_executable(gen_html html.cpp)
target_link_libraries(gen_html
PRIVATE fediblock)
install(TARGETS gen_html
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
RENAME ${PROJECT_NAME}-gen_html)

95
src/generators/html.cpp Normal file
View File

@ -0,0 +1,95 @@
/* This file is part of FediBlock-backend.
* Copyright © 2020 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "html.hpp"
#include "files.hpp"
#include "fs-compat.hpp"
#include "git.hpp"
#include "json.hpp"
#include <exception>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdexcept>
using namespace FediBlock;
namespace FediBlock
{
using std::cerr;
using std::cout;
using std::exception;
using std::ifstream;
using std::runtime_error;
using std::stringstream;
vector<entry_type> read_json_files()
{
vector<entry_type> entries;
auto dir_iter{fs::directory_iterator(files::get_tmpdir() / "repo")};
for (const fs::path &path : dir_iter)
{
if (path.filename().string()[0] == '.')
{
continue;
}
if (path.extension() != ".json")
{
continue;
}
ifstream file(path);
if (!file.good())
{
throw runtime_error{"Could not open file: " + path.string()};
}
stringstream ss;
ss << file.rdbuf();
entries.push_back(json::from_json(ss.str()));
}
return entries;
}
} // namespace FediBlock
int main()
{
git_libgit2_init();
try
{
git::clone();
const auto entries{read_json_files()};
for (const auto &entry : entries)
{
cout << entry.instance << " ";
cout << entry.screenshot_filepath << '\n';
}
}
catch (const exception &e)
{
cerr << "Error: " << e.what() << '\n';
}
files::remove_tmpdir();
git_libgit2_shutdown();
return 0;
}

33
src/generators/html.hpp Normal file
View File

@ -0,0 +1,33 @@
/* This file is part of FediBlock-backend.
* Copyright © 2020 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FEDIBLOCK_BACKEND_HTML_HPP
#define FEDIBLOCK_BACKEND_HTML_HPP
#include "types.hpp"
#include <vector>
namespace FediBlock
{
using std::vector;
[[nodiscard]] vector<entry_type> read_json_files();
} // namespace FediBlock
#endif // FEDIBLOCK_BACKEND_HTML_HPP