eftec/amp-generator-one

使用PHP生成Google AMP网站

1.5 2019-09-01 01:04 UTC

This package is auto-updated.

Last update: 2024-09-07 08:13:15 UTC


README

该库通过使用过程式代码,使用PHP生成Google AMP网站。

Build Status Packagist Total Downloads Maintenance composer php php CocoaPods

此应用程序通过代码简化了AMP网站的生成。编程最简单,只需几行代码就完成了。

例如,假设您想添加一个新部分

$secImage= new SectionModel("The Cupcakes","","/image.jpg");
$secImage->buttons[]=new ButtonModel("More Information","#");
$secImage->buttons[]=new ButtonModel("More Information","#","warning");

$amp->sectionImage($secImage,2250,441);

它将生成以下视觉效果

simple section

它是如何工作的?

use eftec\AmpGeneratorOne\AmpGeneratorOne;
use eftec\AmpGeneratorOne\ButtonModel;
use eftec\AmpGeneratorOne\FooterModel;
use eftec\AmpGeneratorOne\HeaderModel;
use eftec\AmpGeneratorOne\HeadModel;
use eftec\AmpGeneratorOne\LinkModel;
use eftec\AmpGeneratorOne\SectionModel;

include "lib/AmpGeneratorOne.php";
$amp=new AmpGeneratorOne("https://www.canonical.com","https://www.canonical.com/amp");
// # 
$amp->startAmp(new HeaderModel("description","title","favicon.ico"));

// # sidebar (optional)
$amp->sidebar($menu); // $menu is an array of /LinkModel()

// #1 head (the top bar)
$amp->head(new HeadModel("",$base."logo.png"),70,70);

// # example section
$amp->sectionFirst(new SectionModel("Title","Description"));

// # footer
$amp->sectionFooter(new FooterModel("Copyright something(c)","See as desktop"));

amp->render(); // you also could generate a file.

result

平板电脑版本

result

手机版本

result

手机版本(滑动打开)

方法 __construct

AmpGeneratorOne 构造函数。

参数

  • $canonical 原始url。例如 https://www.southprojects.com/somesite (字符串)
  • $base 原始基础url,不带尾部斜杠。例如 https://www.southprojects.com (字符串)
  • $sidebarColor 侧边栏的背景颜色。例如 #ffffff,white,rgb(255,255,255) (字符串)
  • $themecolor . 标志、汉堡的颜色。例如 #ffffff,white,rgb(255,255,255) (字符串)
  • $classSidebar. text-primary,text-secondary,text-success,text-info,text-warning,text-danger,text-white,text-black (字符串)

方法 fixRelativeUrl

修复一个url,将相对url转换为绝对url

参数

  • $url 参数 $url ()
$tmp=$ampgeneratorone->fixRelativeUrlthis(); 

方法 genStructured

生成社交和SEO结构(Twitter卡、Facebook OG和Google Schema)

参数

  • $structured 参数 StructureModel $structured (StructureModel)
$tmp=$ampgeneratorone->genStructuredthis(); 

方法 startAmp

开始生成AMP网站。

参数

  • $param 参数 HeaderModel $param (HeaderModel)
  • $structured 参数 StructureModel $structured (StructureModel)

方法 sidebar

生成侧边栏。

参数

  • $urls 参数 LinkModel[] $urls (LinkModel[])
$tmp=$ampgeneratorone->sidebarthis(); 

方法 head

生成头部导航。

参数

  • $param 参数 HeadModel $param (HeadModel)
  • $width 参数 int $width (整数)
  • $height 参数 int $height (整数)
$tmp=$ampgeneratorone->headthis(); 

方法 sectionFooter

生成amp网站的页脚。

参数

  • $param 参数 FooterModel $param (FooterModel)
$tmp=$ampgeneratorone->sectionFooterthis(); 

方法 sectionAnalytics

生成Google Analytics部分

参数

  • $account UA-XXXXX-Y (字符串)
HeaderModel());
$tmp=$ampgeneratorone->sectionAnalyticsthis(); 

方法 sectionFirst

绘制第一个部分(英雄风格)

参数

  • $content 参数 SectionModel $content (SectionModel)
$tmp=$ampgeneratorone->sectionFirstthis(); 

方法 sectionImageButton

生成一个带有单个按钮的部分。

参数

  • $content 参数 SectionModel $content (SectionModel)
  • $fullscreen 参数 bool $fullscreen (布尔值)
$tmp=$ampgeneratorone->sectionImageButtonthis(); 

方法 sectionText

生成一个带有文本的部分。

参数

  • $content 参数 SectionModel $content (SectionModel)
$tmp=$ampgeneratorone->sectionTextthis(); 

方法 sectionTextQuote

生成引用文本

参数

  • $content 参数 SectionModel $content (SectionModel)
$tmp=$ampgeneratorone->sectionTextQuotethis(); 

方法 sectionUL

生成一个无序列表部分

参数

  • $links 参数 LinkModel[] $links (LinkModel[])
$tmp=$ampgeneratorone->sectionULthis(); 

方法 sectionOL

生成一个有序列表部分

参数

  • $links 参数 LinkModel[] $links (LinkModel[])
$tmp=$ampgeneratorone->sectionOLthis(); 

方法 sectionButtons

生成一个包含一个(或多个)按钮的部分。

参数

  • $content 参数 SectionModel $content (SectionModel)
$tmp=$ampgeneratorone->sectionButtonsthis(); 

方法 sectionCols

生成一个带有列的部分

参数

  • $contents 参数 SectionModel[] $contents (SectionModel[])
$tmp=$ampgeneratorone->sectionColsthis(); 

方法 sectionHeaderCentral

生成一个包含按钮的头部中央部分。

参数

  • $content 参数 SectionModel $content (SectionModel)
$tmp=$ampgeneratorone->sectionHeaderCentralthis(); 

方法 sectionRaw

参数

方法 sectionImageContent

生成一个包含图像内容的部分。

参数

  • $content 参数 SectionModel $content (SectionModel)
  • $width 参数 $width ()
  • $height 参数 $height ()
$tmp=$ampgeneratorone->sectionImageContentthis(); 

方法 sectionImageContentLeft

生成一个包含左侧图像内容的部分。

参数

  • $content 参数 SectionModel $content (SectionModel)
  • $width 参数 $width ()
  • $height 参数 $height ()
$tmp=$ampgeneratorone->sectionImageContentLeftthis(); 

方法 sectionTable

生成一个表格

参数

  • $cols 参数 array $cols (数组)
$tmp=$ampgeneratorone->sectionTablethis(); 

方法 sectionImage

它生成一个图像。需要图像大小来计算比例

参数

  • $content 参数 SectionModel $content (SectionModel)
  • $width 参数 int $width (整数)
  • $height 参数 int $height (整数)
$tmp=$ampgeneratorone->sectionImagethis(); 

方法部分GMapFull

它生成一个谷歌地图部分。不能定位在网站顶部30%的位置(Amp限制)

参数

  • $content 参数 SectionModel $content (SectionModel)
  • $googleMapUrl 参数字符串 $googleMapUrl (字符串)
  • $placeholder 参数字符串 $placeholder (字符串)
$tmp=$ampgeneratorone->sectionGMapFullthis(); 

方法部分GMapBoxed

它生成一个带框的谷歌地图部分。不能定位在网站顶部30%的位置(Amp限制)

参数

  • $content 参数 SectionModel $content (SectionModel)
  • $googleMapUrl 参数字符串 $googleMapUrl (字符串)
$tmp=$ampgeneratorone->sectionGMapBoxedthis(); 

方法部分Navigation

它生成一个页脚导航

参数

  • $content 参数 SectionModel $content (SectionModel)
  • $image 参数字符串 $image (字符串)
  • $width 参数 int $width (整数)
  • $height 参数 int $height (整数)
  • $navCol1 参数 LinkModel[] $navCol1 (LinkModel[])
  • $navCol2 参数 LinkModel[] $navCol2 (LinkModel[])
  • $navCol3 参数 LinkModel[] $navCol3 (LinkModel[])
  • $navCol4 参数 LinkModel[] $navCol4 (LinkModel[])
$tmp=$ampgeneratorone->sectionNavigationthis(); 

方法部分ColImage

它生成一个包含图像和文本的部分。

参数

  • $contents 参数 SectionModel[] $contents (SectionModel[])
  • $width 参数 int $width (整数)
  • $height 参数 int $height (整数)
  • $maxCol 参数 int $maxCol (整数)
$tmp=$ampgeneratorone->sectionColImagethis(); 

方法 genModifyStyle

参数

方法 setBackgroundColor

流畅操作,它更改下一个部分的背景颜色

参数

  • $color 示例 #ffffff,rgb(30,30,30),white (字符串)
$tmp=$ampgeneratorone->setBackgroundColorthis(); 

方法 setBgImage

流畅操作,它更改下一个部分的背景图像

参数

  • $bgImage 参数字符串 $bgImage (字符串)
$tmp=$ampgeneratorone->setBgImagethis(); 

方法 setClassTextColor

流畅操作,它设置文本的类

参数

  • $class text-primary,text-secondary,text-success,text-info,text-warning,text-danger,text-white,text-black (字符串)
$tmp=$ampgeneratorone->setClassTextColorthis(); 

方法 setPadding

流畅操作,它更改填充

参数

  • $top 参数 $top ()
  • $bottom 参数 $bottom ()
$tmp=$ampgeneratorone->setPaddingthis(); 

方法 resetDefault

参数

方法 setDefault

它重置为默认的背景颜色和文本类

参数

  • $backGroundColor 示例 #ffffff,rgb(30,30,30),white (字符串)
  • $classTextColor text-primary,text-secondary,text-success,text-info,text-warning,text-danger,text-white,text-black (字符串)

方法 image

参数

方法 table

参数

方法 render

它渲染结果页面。

参数

方法 renderToFile

它将结果渲染到文件

参数

  • $filename 参数字符串 $filename (字符串)

方法 genLink

仅当数组包含信息或链接不为空时,才生成数组的第一个链接。

参数

  • $url 参数 LinkModel|LinkModel[] $url (LinkModel|LinkModel[])
$tmp=$ampgeneratorone->genLinkthis(); 

方法 genButton

仅当数组包含信息或链接不为空时,才生成数组的第一个链接。

参数

  • $url 参数 ButtonModel|ButtonModel[] $url (ButtonModel|ButtonModel[])

注意:您可以更改颜色。

有效性

您可以在Google搜索验证上验证您的amp。

Google Amp Validation

版本

  • 1.5 2019-08-31 删除了部分中的min-width。
  • 1.4 2019-06-04 一些修复。
  • 1.3 2018-11-03 添加了Phpunit和travis。
  • 1.1 2018-09-20 修复了一些错误。
  • 1.0 2018-09-08 第一个非beta版本
  • 0.3 2018-09-07 清理。
  • 0.2 2018-09-06 工作版本。
  • 0.1 2018-08-20 第一个原型

示例演示

查看最终结果

Full Project