Jump to content

Downloadable documentation


APEXnow
 Share

Go to solution Solved by reepblue,

Recommended Posts

  • Solution

You can download the entire documentation here and preview the .md files in Visual Studio Code.

UltraEngine/Documentation: Documentation contents for Ultra Engine (github.com)

  • Like 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Using the table of contents JSON file it would be possible for anyone to read all the MD files, and output an HTML page or pages with the entire contents. That could even be converted to a PDF.

https://github.com/UltraEngine/Documentation/blob/master/toc.json
https://github.com/erusev/parsedown
 

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Here is some AI-generated code that might help get you started. No idea if this is right or not!

<?php

// Include the Parsedown library
require 'vendor/autoload.php';

// Function to fetch JSON data from a URL
function fetchJson($url) {
    $json = file_get_contents($url);
    return json_decode($json, true);
}

// Function to generate HTML from topics
function generateHtml($topics) {
    $html = '<html><head><title>Documentation</title></head><body>';
    $html .= '<h1>Documentation</h1>';
    $html .= '<ul>';

    foreach ($topics as $topic) {
        $html .= '<li>' . htmlspecialchars($topic['title']);
        
        // Check if there are subtopics
        if (isset($topic['topics'])) {
            $html .= '<ul>';
            $html .= generateHtml($topic['topics']);
            $html .= '</ul>';
        }

        $html .= '</li>';
    }

    $html .= '</ul>';
    $html .= '</body></html>';
    return $html;
}

// Function to read Markdown files from GitHub and convert to HTML
function readMarkdownFiles($topics) {
    $parsedown = new Parsedown();
    $htmlContent = '';

    foreach ($topics as $topic) {
        if (isset($topic['filename'])) {
            // Determine the correct URL based on the filename case
            $baseUrl = (ctype_lower($topic['filename'])) 
                ? 'https://raw.githubusercontent.com/UltraEngine/Documentation/refs/heads/master/' 
                : 'https://raw.githubusercontent.com/UltraEngine/Documentation/refs/heads/master/CPP/';
                
            $markdownUrl = $baseUrl . $topic['filename'] . '.md'; // URL to the markdown file
            $markdownContent = file_get_contents($markdownUrl);
            if ($markdownContent !== false) {
                $htmlContent .= '<h2>' . htmlspecialchars($topic['title']) . '</h2>';
                $htmlContent .= $parsedown->text($markdownContent);
            }
        }

        // Recursively read subtopics
        if (isset($topic['topics'])) {
            $htmlContent .= readMarkdownFiles($topic['topics']);
        }
    }

    return $htmlContent;
}

// Main execution
$jsonUrl = 'https://raw.githubusercontent.com/UltraEngine/Documentation/refs/heads/master/toc.json';
$topics = fetchJson($jsonUrl)['topics'];

$html = generateHtml($topics);
$markdownContent = readMarkdownFiles($topics);

// Combine the generated HTML with the Markdown content
$finalHtml = str_replace('<body>', '<body>' . $markdownContent, $html);

// Save the final HTML to a file
file_put_contents('documentation.html', $finalHtml);

echo "Documentation HTML file generated successfully!";
?>

Or a CPP version:

#include <iostream>
#include <fstream>
#include <string>
#include <curl/curl.h>
#include <nlohmann/json.hpp>
#include <sstream>
#include <regex>

using json = nlohmann::json;

// Function to write data received from curl to a string
size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* userp) {
    size_t totalSize = size * nmemb;
    userp->append((char*)contents, totalSize);
    return totalSize;
}

// Function to fetch JSON data from a URL
std::string fetchJson(const std::string& url) {
    CURL* curl;
    CURLcode res;
    std::string readBuffer;

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    return readBuffer;
}

// Function to generate HTML from topics
std::string generateHtml(const json& topics) {
    std::ostringstream html;
    html << "<html><head><title>Documentation</title></head><body>";
    html << "<h1>Documentation</h1><ul>";

    for (const auto& topic : topics) {
        html << "<li>" << topic["title"].get<std::string>();
        if (topic.contains("topics")) {
            html << "<ul>" << generateHtml(topic["topics"]) << "</ul>";
        }
        html << "</li>";
    }

    html << "</ul></body></html>";
    return html.str();
}

// Function to read Markdown files from GitHub and convert to HTML
std::string readMarkdownFiles(const json& topics) {
    std::ostringstream htmlContent;
    CURL* curl;
    CURLcode res;

    for (const auto& topic : topics) {
        if (topic.contains("filename")) {
            std::string filename = topic["filename"].get<std::string>();
            std::string baseUrl = (std::all_of(filename.begin(), filename.end(), ::islower))
                ? "https://raw.githubusercontent.com/UltraEngine/Documentation/refs/heads/master/"
                : "https://raw.githubusercontent.com/UltraEngine/Documentation/refs/heads/master/CPP/";

            std::string markdownUrl = baseUrl + filename + ".md";
            std::string markdownContent = fetchJson(markdownUrl);

            if (!markdownContent.empty()) {
                htmlContent << "<h2>" << topic["title"].get<std::string>() << "</h2>";
                // Convert Markdown to HTML (simple replacement for demonstration)
                std::regex headerRegex(R"(# (.+))");
                markdownContent = std::regex_replace(markdownContent, headerRegex, "<h1>$1</h1>");
                htmlContent << markdownContent;
            }
        }

        if (topic.contains("topics")) {
            htmlContent << readMarkdownFiles(topic["topics"]);
        }
    }

    return htmlContent.str();
}

// Main execution
int main() {
    std::string jsonUrl = "https://raw.githubusercontent.com/UltraEngine/Documentation/refs/heads/master/toc.json";
    std::string jsonData = fetchJson(jsonUrl);
    
    // Parse JSON data
    json topics = json::parse(jsonData)["topics"];

    std::string html = generateHtml(topics);
    std::string markdownContent = readMarkdownFiles(topics);

    // Combine the generated HTML with the Markdown content
    std::string finalHtml = std::regex_replace(html, std::regex("<body>"), "<body>" + markdownContent);

    // Save the final HTML to a file
    std::ofstream outFile("documentation.html");
    outFile << finalHtml;
    outFile.close();

    std::cout << "Documentation HTML file generated successfully!" << std::endl;
    return 0;
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...