this post was submitted on 18 Jul 2026
43 points (95.7% liked)

Technology

42961 readers
304 users here now

This is the official technology community of Lemmy.ml for all news related to creation and use of technology, and to facilitate civil, meaningful discussion around it.


Ask in DM before posting product reviews or ads. All such posts otherwise are subject to removal.


Rules:

1: All Lemmy rules apply

2: Do not post low effort posts

3: NEVER post naziped*gore stuff

4: Always post article URLs or their archived version URLs as sources, NOT screenshots. Help the blind users.

5: personal rants of Big Tech CEOs like Elon Musk are unwelcome (does not include posts about their companies affecting wide range of people)

6: no advertisement posts unless verified as legitimate and non-exploitative/non-consumerist

7: crypto related posts, unless essential, are disallowed

founded 7 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] eleitl@lemmy.zip 6 points 1 day ago (1 children)
[–] Zarobi@aussie.zone 2 points 1 day ago (2 children)

I prefer the flexibility of PHP personally, but there's pros and cons to everything. For example, I don't really see how setting up 11ty is any easier than a 10 line build.php. Might as well keep it simple

[–] squirrel@cake.kobel.fyi 2 points 15 hours ago (1 children)

I tried SSGs like 11ty, but they are overkill for simple things.

I'd be interested in the 10 line build.php. Care to share?

[–] Zarobi@aussie.zone 1 points 13 hours ago (1 children)

Sure, I'm typing it out on my phone though so excuse any mistakes:

Tap for build.sh

# build.sh
php build.php

Tap for build.php

// build.php
<?php

// Just contains all the directory definitions and utilities in one place
require once __DIR__ . './bootstrap.php';
require once __DIR__ . './utils.php';

// Static assets
ensureDir(DIST_DIR);
copy_all_files(ASSETS_DIR, DIST_DIR);

$files = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator(PAGES_DIR)
);

// Build each page
foreach ($files as $file) {
    if ($file->isDir()) continue;
    $path = $file->getPathname();

    // only build .php pages (skip partials)
    if (!str_ends_with($path, '.php')) continue;

    $relative = str_replace('pages/', '', str_replace(SRC_DIR . '/', '', $path));
    $output = str_replace('.php', '/index.html', $relative);

    echo $relative . "\n";
    if ($relative == 'index.php') {
        $outputPath = DIST_DIR . '/index.html';
    }
    else if (str_ends_with($output, 'index/index.html')) {
        $output = str_replace('index/index.html', 'index.html', $output);
        $outputPath = DIST_DIR . '/' . $output;
    }
    else {
        $outputPath = DIST_DIR . '/' . $output;
    }

    ensureDir(dirname($outputPath));
    ob_start();
    include $path;
    $html = ob_get_clean();

    echo $outputPath . "\n";
    file_put_contents($outputPath, $html);
}

echo "Build complete\n";

Tap for utils.php

// utils.php

function ensureDir($path) {
    if (!is_dir($path)) {
        mkdir($path, 0777, true);
    }
}

function copy_all_files($source_dir, $target_dir) {
    $dir_obj = opendir($source_dir);
    @mkdir($target_dir);
    while ($file = readdir($dir_obj)) {
        if ($file != "." && $file != "..") {
            if (is_dir($source_dir . "/" . $file)) {
                copy_all_files($source_dir . "/" . $file, $target_dir . "/" . $file);
            } else {
                copy($source_dir . "/" . $file, $target_dir . "/" . $file);
            }
        }
    }
    closedir($dir_obj);
}

Tap for bootstrap.php

<?php
define('ROOT_DIR', __DIR__);
    define('DIST_DIR',  ROOT_DIR . '/dist');
    define('SRC_DIR',   ROOT_DIR . '/src');
        define('PAGES_DIR',     SRC_DIR . '/pages');
// etc

I stripped out all the database stuff because as my site grew I kept expanding on it and I needed a database.

Mine will also probably be longer than average because I wanted fancy stuff like my source pages being just "about.php" instead of "about/index.php", but I wanted the output to be "about/index.html" so it got way more complicated than it needed to be. But again most of those lines in the for loop are just me being obsessive compulsive about my own directory structure 😂. I also didn't count the utilities functions in my original line count because to me that's equivalent of importing a module; I didn't write that file, I just copy pasted it from online. You could probably find a simpler build script online.

Tap for example.php

<?php
$pageTitle = 'Example';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <?php include PARTIALS_DIR . '/head.php'; ?>
    <link rel="stylesheet" href="/styles/example.css" />
</head>
<body>
    <?php include PARTIALS_DIR . '/header.php'; ?>
    <?php include PARTIALS_DIR . '/noscript.php'; ?>
    <main>
        <h1>example</h1>
    </main>

    <?php include PARTIALS_DIR . '/footer.php'; ?>
    <?php include PARTIALS_DIR . '/global-scripts.php'; ?>
</body>
</html>

[–] squirrel@cake.kobel.fyi 1 points 11 hours ago

Thank you very much. I'll try to comprehend all this later, since I'm on the phone as well :)

[–] eleitl@lemmy.zip 2 points 1 day ago (1 children)

PHP is additional vulnerability, while static html is bullet proof, as long as http server is safe and up to date.

[–] Zarobi@aussie.zone 1 points 1 day ago (1 children)

How is PHP a vulnerability if it never leaves your machine and you only use it to build the HTML?

[–] eleitl@lemmy.zip 2 points 1 day ago (1 children)

Oh, if you're only using it to generate static html it's of course safe. I would prefer minimal markdown for blogs, though.

[–] Zarobi@aussie.zone 2 points 1 day ago

I guess I just really like HTML. Any excuse to write actual HTML makes me happy