lausek/lowebf

此包的最新版本(v0.6.4)没有提供许可证信息。

网页后端框架

v0.6.4 2022-06-20 22:12 UTC

This package is auto-updated.

Last update: 2024-09-30 01:46:37 UTC


README

lowebf 是一个用于创建简单网站的微型框架。它提供了清晰的接口来分离网站逻辑和内容。 lowebf\Environment 类提供了针对特定用例的模块。

特性

  • 使用您喜欢的格式(JSON、YAML、Markdown)定义网站内容和配置
  • SCSS 编译器
  • 处理操作结果的输出类型
  • Markdown 扩展,用于通过 URL 嵌入视频

非特性

  • 没有数据库连接
  • 没有模型
  • 没有路由层

模块

示例

composer require lausek/lowebf
composer update
<?php

// example implementation of `site/public/index.php`.
// your document root should be set to `site/public` to avoid
// request escapes into other directories.

// this only works if the vendor directory was added to 
// the include path inside `php.ini`.
require "autoload.php";

// create the default instance of our environment
$env = lowebf\Environment::getInstance();

// read a value from the php superglobals
// passed to your current script. this is equal to:
//
//     $pageNumber = $_GET["p"] ?? 1;
//
// but it allows you to terminate the program 
// using `unwrapOrExit($env)` if the variable is not present.
$pageNumber = $env->globals()->get("p")->unwrapOr(1);

// load a specific post page from your `data/posts` directory.
// by default, 15 posts are displayed in one page.
// if the page loading fails -> terminate the script and return
// a "404 - not found" error.
$page = $env->posts()->loadPage($pageNumber)->unwrapOrExit($env, 404);
$maxPage = $env->posts()->getMaxPage();

// render the overview with the selected page
$env->view()->render("index.html",
    [
        "entries" => $page,
        "pageCurrent" => $pageNumber,
        "pageMax" => $maxPage,
    ]
);

目录结构

  • cache/
    • thumbs/:帖子缩略图
    • twig/:Twig 模板的缓存
  • data/
    • content/:其他内容数据
    • download/:可供下载的文件
    • media/
      • img/:图片:png、jpeg、gif
      • vid/:视频:mp4、avi
      • misc/:其他文件格式,如:pdf、json
    • posts/:Markdown 格式的经常更新的新闻
    • config.yaml:网站的通用配置
  • site/
    • css/:
    • img/:
    • js/:
    • public/:可访问的 PHP 文件
      • route.php:用于提供所有类型的静态文件
    • template/:Twig 模板目录

注意:如果不需要,则大多数目录和文件都不是必需的。