src/ViewUnit.php
static public function seo(string $page, array $params = []): string
    {
        // 取全部SEO配置信息
        try {
            $rules = config('application', 'seo');
        } catch (ConfigException $e) {
            trigger_error('缺少SEO相关配置(application|seo)', E_USER_ERROR);
            exit;
        }
        if (!isset($rules[$page])) {
            $page = '_default';
        }

        // 取本SEO配置 信息
        $rule = $rules[$page];

        // SEO三项
        $title = $rule['title'];
        $keywords = $rule['keywords'];
        $description = $rule['description'];

        // 替换,因变量不会太多,逐个替换
        foreach ($params as $key => $value) {
            $title = str_replace('{$' . $key . '}', $value, $title);
            $keywords = str_replace('{$' . $key . '}', $value, $keywords);
            $description = str_replace('{$' . $key . '}', $value, $description);
        }

        // 构造 HTML中SEO三项的语法
        $ret = '<title>' . $title . '</title>' . "\n";
        $ret .= '<meta name="keywords" content="' . $keywords . '"/>' . "\n";
        $ret .= '<meta name="description" content="' . $description . '"/>' . "\n";

        return $ret;
    }
static public function seo(string $page, array $params = []): string
    {
        // 取全部SEO配置信息
        try {
            $rules = config('application', 'seo');
        } catch (ConfigException $e) {
            trigger_error('缺少SEO相关配置(application|seo)', E_USER_ERROR);
            exit;
        }
        if (!isset($rules[$page])) {
            $page = '_default';
        }

        // 取本SEO配置 信息
        $rule = $rules[$page];

        // SEO三项
        $title = $rule['title'];
        $keywords = $rule['keywords'];
        $description = $rule['description'];

        // 替换,因变量不会太多,逐个替换
        foreach ($params as $key => $value) {
            $title = str_replace('{$' . $key . '}', $value, $title);
            $keywords = str_replace('{$' . $key . '}', $value, $keywords);
            $description = str_replace('{$' . $key . '}', $value, $description);
        }

        // 构造 HTML中SEO三项的语法
        $ret = '<title>' . $title . '</title>' . "\n";
        $ret .= '<meta name="keywords" content="' . $keywords . '"/>' . "\n";
        $ret .= '<meta name="description" content="' . $description . '"/>' . "\n";

        return $ret;
    }
生成SEO相关内容

@param string $page
@param array $params
@return string