Skip to content

Commit

Permalink
Merge pull request #1 from ahmetcelikezer/v1.0.0
Browse files Browse the repository at this point in the history
V1.0.0
  • Loading branch information
ahmetcelikezer authored Sep 24, 2019
2 parents d370e0f + da8aa9c commit 8cf343c
Show file tree
Hide file tree
Showing 12 changed files with 774 additions and 144 deletions.
1 change: 1 addition & 0 deletions AhcTwigSeoBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class AhcTwigSeoBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
}
}
5 changes: 5 additions & 0 deletions DependencyInjection/AhcTwigSeoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class AhcTwigSeoExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$config = $this->processConfiguration(new Configuration(), $configs);

$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
$loader->load('ahc_twig_seo.yaml');

$container->setParameter('ahc_twig_seo_config', $config);
}
}
40 changes: 40 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Ahc\TwigSeoBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('ahc_twig_seo');

$treeBuilder->getRootNode()
->children()
->arrayNode('groups')
->arrayPrototype()
->children()
->arrayNode('arguments')
->scalarPrototype()
->end()
->end()
->arrayNode('tags')
->variablePrototype()
->end()
->end()
->arrayNode('methods')
->variablePrototype()
->end()
->end()
->end()
->end()
->end()
->end()
;

return $treeBuilder;

}
}
116 changes: 116 additions & 0 deletions Entity/Element.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

namespace Ahc\TwigSeoBundle\Entity;

class Element
{
/**
* @var array
*/
private $arguments;

/**
* @var array
*/
private $tags;

/**
* @var array
*/
private $methods;

/**
* @var array
*/
private $contentArray;

/**
* @var string
*/
private $group;

/**
* @var array
*/
private $argumentValues;

public function __construct(string $group = null)
{
$this->setGroup($group);
}

/**
* @return string
*/
public function getGroup(): string
{
return $this->group;
}

public function setGroup(string $group): self
{
$this->group = $group;

return $this;
}

public function getArguments(): ?array
{
return $this->arguments;
}

public function setArguments(array $arguments): self
{
$this->arguments = $arguments;

return $this;
}

public function getArgumentValues(): ?array
{
return $this->argumentValues;
}

public function setArgumentValues(array $values): self
{
$this->argumentValues = $values;

return $this;
}

public function getTags(): ?array
{
return $this->tags;
}

public function setTags(array $tags): self
{
$this->tags = $tags;

return $this;
}

public function getMethods(): ?array
{
return $this->methods;
}

public function setMethods(array $methods): self
{
$this->methods = $methods;

return $this;
}

public function getContentArray(): ?array
{
return $this->contentArray;
}

public function setContentArray(array $content): self
{
$this->contentArray = $content;

return $this;
}
}
79 changes: 0 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +0,0 @@
# Twig Seo Bundle
This bundle includes a twig extension to print SEO meta tags easily. This is an early version of bundle, new features will be added soon.
> Note: This is an early version of the extension bundle! The stable version will release soon. So next version(s) may not support this version's feature(s)!
## Installation
You can install this bundle with composer.
```bash
composer require ahc/twigseobundle
```

## Methods
* [Seo Base](#seo-base)
* [Seo Title](#seo-title)
* [Seo Description](#seo-description)
* [Seo Image](#seo-image)
* [Seo Page](#seo-page)
### Seo Base
This method print a basic tags.
```twig
{{ seoBase() }}
```
This method includes the following tags:
```html
<meta property="og:type" content="website" />
```
---
### Seo Title
This method print title tags with og title's. It takes only one string parameter to set the title.
```twig
{{ seoTitle('Your Title') }}
```
This method includes the following tags:
```html
<title>Your Title</title>
<meta property="og:site_name" content="Your Title">
<meta property="og:title" content="Your Title" />
<meta name="twitter:title" content="Your Title" />
```
---
### Seo Description
This method print a description tags. It takes only one string parameter to set the description.
```twig
{{ seoDescription('Description text...') }}
```
This method includes the following tags:
```html
<meta name="description" content="Description text...">
<meta property="og:description" content="Description text..." />
<meta name="twitter:description" content="Description text..." />
```
---
### Seo Image
This method print the og image tags. It takes only one string parameter for set absolute image path.
```twig
{{ seoImage('path/image_file') }}
```
> Warning! The image path must be a absolute path!!
This method includes the following tags:
```html
<meta property="og:image" content="path/image_file" />
<meta name="twitter:image" content="path/image_file" />
<link rel="image_src" href="path/image_file" />
```
---
### Seo Page
Sometimes every page has it's own meta tags. This method will set title and description of current page. It takes one array parameter including `title` and `description`.
```twig
{{ seoPage({ title: 'Page Title', description: 'Page Description' }) }}
```
The method includes the following tags:
```html
<title>Page Title</title>
<meta name="description" content="Page Description">
```




46 changes: 46 additions & 0 deletions Resources/config/ahc_twig_seo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
ahc_twig_seo:
groups:

default_base:
arguments:
title: '%%title%%'
description: '%%description%%'
tags:
- '<meta charset="utf-8">'
- '<meta property="og:type" content="website" />'
- '<meta content="IE=edge" http-equiv="X-UA-Compatible" />'
- '<meta content="width=device-width, initial-scale=1" name="viewport" />'

# TODO: Feature loop able groups for same data
#default_favicons:
# arguments:
# image_path: '%%image_path%%'
# size: '%%size%%'
# mime_type: '%%ext%%'
# tags:
# - '<link rel="icon" type="%%ext%%" sizes="%%size%%" href="%%image_path%%">'

default_title:
arguments:
title: '%%title%%'
tags:
- '<title>%%title%%</title>'
- '<meta property="og:site_name" content="%%title%%">'
- '<meta property="og:title" content="%%title%%" />'
- '<meta name="twitter:title" content="%%title%%" />'

default_description:
arguments:
description: '%%description%%'
tags:
- '<meta name="description" content="%%description%%" />'
- '<meta property="og:description" content="%%description%%" />'
- '<meta name="twitter:description" content="%%description%%" />'

default_og_images:
arguments:
imagePath: '%%image_path%%'
tags:
- '<meta property="og:image" content="%%image_path%%" />'
- '<meta name="twitter:image" content="%%image_path%%" />'
- '<link rel="image_src" href="%%image_path%%" />'
12 changes: 12 additions & 0 deletions Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,17 @@ services:

Ahc\TwigSeoBundle\Twig\AhcTwigSeoExtension:
public: false
arguments:
- '@ahc.twig_seo_bundle.element_manager'
tags:
- { name: twig.extension }

ahc.twig_seo_bundle.configuration_manager:
class: 'Ahc\TwigSeoBundle\Utils\ConfigurationManager'
arguments:
- '%ahc_twig_seo_config%'

ahc.twig_seo_bundle.element_manager:
class: 'Ahc\TwigSeoBundle\Utils\ElementManager'
arguments:
- '@ahc.twig_seo_bundle.configuration_manager'
Loading

0 comments on commit 8cf343c

Please sign in to comment.