Giter Club home page Giter Club logo

amped-laravel's Introduction

Amped Laravel

This package adds possibility to convert existing html content to amp-html. The package uses AMP Plugin for WordPress for content sanitizing and some helper functions from Wordpress for amp-wp plugin.

AMP is a fast-growing framework, but unfortunately, currently, there are no (or at least I can't find it) any working solutions, which can help to provide a valid html to amp-html code converter. According to ampproject/amp-wp#2315, @amproject is preparing to release a PHP-library independent from any CMS, but until that time using amp-wp plugin as a content sanitizer is an easiest solution, even if it has many Wordpress-related code. If you have any issue with package sanitizer, you can easily swap it with your own, just making changes in provided config.

Requirements

  • PHP >= 7.3
  • Laravel >= 6.x

Update from versions < 0.4.x

You need to change repository url in your composer.json from https://github.com/ampproject/amp-wp to https://github.com/arrowsgm/amp-wp, this is a hard-forked version 1.4.4 of the ampproject/amp-wp package with updated dependencies.

Installation

Add to your composer.json repositories section link to amp-wp plugin:

...
"repositories": [
...
    {
      "type": "vcs",
      "url": "https://github.com/arrowsgm/amp-wp"
    }
  ]
...

when require package as usual:

composer require arrowsgm/amped-laravel

Using

You can publish configuration with artisan command:

php artisan vendor:publish --tag=amped-config

or just create amped.php file in the config directory and change required params only.

To convert existing content use provided Amped facade:

...
use Arrowsgm\Amped\Facades\Amped;
...
class PostController extends Controller
{
    ...
    public function show(Post $post)
    {
        ...
        $amp_content = Amped::convert($post->content);
        ...
    }
    ...
}

You can use Amped facade in the blade templates, alias already provided:

<div class="amp-content">{{ Amped::convert($post->content) }}</div>

Amped class also have inlineCss method to adding custom styles from css file:

{!! Amped::inlineCss('amp.css') !!}

and you can set base amp styles directory with amp_custom_css_path config param.

isDevParam method is useful for amp link building. It returns #development=1 string if laravel application debugging is on:

<a 
    href="{{ route('post.show', $prev_post->slug) }}/amp{!! Amped::isDevParam() !!}"
    class="links links-prev">{{ $prev_post->name }}</a>

and you can easily navigate through the existing posts with in-browser AMP validation enabled.

amped-laravel's People

Contributors

arrowsgm avatar c0b41 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.