yawik/landingpages

为职位搜索创建着陆页以优化SEO

安装: 172

依赖: 0

建议者: 0

安全: 0

星级: 0

关注者: 2

分支: 0

开放性问题: 6

类型:yawik-module

v0.3.0 2020-12-15 08:56 UTC

README

为职位搜索创建着陆页

概述

  • 可配置的着陆页URL
  • 在任何深度将着陆页分组在类别中
  • 动态组合类别或着陆页;无论是通过配置还是视图助手
  • 方便的视图助手以显示着陆页的链接

安装

要将此作为yawik模块使用,您需要在您的YAWIK项目中包含它

composer require yawik/landingpages

要贡献,您需要克隆存储库

git clone git@github.com:yawik/landingpages.git
cd landingpages
composer install

使用以下命令启动本地Web服务器:

php -S localhost:8000 -t test/sandbox/public test/sandbox/public/router.php

composer serve

您应该能够通过 https://:8000 访问您的yawik

使用

配置

config/landingpages.config.local.php.dist 复制到您的autoload目录,并将其重命名为 landingpages.config.local.php

在此文件中,您可以配置路由、着陆页和类别

$route = '/landingpage/%slug%';
  • 此路由是 "lang" 路由的子路由(始终以 "/" 前缀,例如:"/en/")
  • 字符串 "%slug%" 必须在定义中 - 这将用着陆页slug替换(见下文)
  • 路由不得包含"--"(两个连字符)- 这用于表示组合的类别
$landingpages = [];

在此,您将配置类别、着陆页和组合项作为嵌套数组。数组键是项的slug - 即使在嵌套数组中,它们也必须是唯一的。

有三种“类型”的项

  • 类别
    • 具有数组键 'items',其值是一个slug > 项的数组
    • 可能具有数组键 'text',其值用作显示名称
  • 着陆页
    • 具有数组键 'query',这是一个数组,其中您指定搜索表单字段的值
      • 'q':搜索文本
      • 'l':位置
      • 'd':距离
    • 可能具有数组键 'params',这是一个数组,它将额外的路由参数注入到RouteMatch对象中。
    • 可能具有数组键 'text',其值用作显示名称
  • 组合项
    • 具有数组键 'combine',其值是一个slug的数组。这些slug需要在配置数组中定义。
    • 可能具有数组键 'glue',其值用作组合项显示名称之间的连接字符串。
    • 可能具有数组键 'text',其值用作显示名称。

示例配置

<?php
$landingpages = [
  'top' => [
    'text' => 'Top is a category'
    'items' => [
      'topPage' => [
        'text' => 'This is a landing page',
        'query' => [
          'q' => 'manager',
          'l' => 'Frankfurt am Main, Germany',
          'd' => 50
        ],
        'params' => [
          'param1' => 'Additional route parameter',
        ],
      ],
    ],
  ],
  'middle' => [
    'text' => 'This combines top and bottom',
    'combine' => ['top', 'bottom'],
    'glue' => 'and',
  ],
  'bottom' => [
    'text' => 'Bottom category',
    'items' => [
      'bottomPage' => [
        'text' => 'Also a landing page',
        'query' => [
          'q' => 'executive',
        ],
      ],
      'executive-manager' => [
        'text' => 'you can also combine landing pages',
        'combine' => ['topPage', 'bottomPage'],
        'glue' => 'combined with',
      ],
    ],
  ],
];

渲染

此模块提供两个视图助手,一个用于轻松渲染指向着陆页或类别的链接,另一个用于在着陆页上访问着陆页实体。

着陆页助手

<?=$this->landingpages(string|array $slug, string $partial, array $values)?>
  • $slug 是一个字符串,对应于配置中定义的slug,或者是一个slug的数组。在后一种情况下,传递给 $partial 的结果类别实体是所有slugs的组合。您可以通过具有 'glue' 键的数组条目指定要使用的连接符。

  • $partial 是用于渲染链接的视图部分名称。目前,此模块只提供了一个部分,用作默认值
    landingpages/button

  • $values 是一个变量名 > 值对的数组,要注入到视图部分中。
    类别实体作为 'category' 键传递。

着陆页助手

<?=$this->landingpage()?>
  • 如果没有调用着陆页路由,则返回 null
  • 充当着陆页实体的代理
  • 提供 isCombined() 方法,用于快速检查当前着陆页是否由多个子页码组合而成。

示例

<?php
// get the landingpage params
$params = $this->landingpage()->getParams();

// render a combination of this landingpage with a category
if ($this->landingpage()):
    if ($this->landingpage()->getCategory()->getName() == 'top'):
        echo $this->landingpages(
            [
                $this->landingpage()->getSlug(),
                'bottom',
                'glue' => 'and'
            ]
        );
    elseif ($this->landingpage()->getCategory()->getName() == 'bottom'):
        // ...
    endif;
endif;  

许可

麻省理工学院