Skip to content

Commit

Permalink
new feature - allows for custom json to be paste
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmassen committed Sep 14, 2018
1 parent 21cdc53 commit 8c90aa4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions blueprints.yaml
Expand Up @@ -105,6 +105,16 @@ form:
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool
customjson:
type: toggle
label: Enable Custom Json Microdata
highlight: 1
default: 1
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool
mdcolumn2:
type: column
fields:
Expand Down
13 changes: 12 additions & 1 deletion blueprints/seo.yaml
Expand Up @@ -821,7 +821,18 @@ form:
type: text
label: PLUGIN_SEO.RESTAURANT_TELEPHONE
field_classes: togglerestaurant

header.custom_json_condition:
type: conditional
condition: "config.plugins.seo.customjson ? 'true' : 'false'"
fields:
header.add_json:
type: list
label: Paste custom JSON-ld Microdata
fields:
.custom_json:
type: textarea
label: Or paste here your own JSON-ld Microdata
placeholder: (do not include the script tags)
facebookfields:
type: tab
title: Facebook
Expand Down
12 changes: 11 additions & 1 deletion seo.php
Expand Up @@ -165,6 +165,8 @@ public function onPageInitialized()
$config = $this->mergeConfig($page);
$content = strip_tags($page->content());
$assets = $this->grav['assets'];
$customjson = "";
$outputcustomjson = "";
$pattern = '~((\/[^\/]+)+)\/([^\/]+)~';
$replacement = '$1';
$outputjson = "";
Expand Down Expand Up @@ -698,14 +700,22 @@ public function onPageInitialized()
}*/
// $microdata = array_map('array_filter', $microdata);
$microdata = $this->array_filter_recursive($microdata);
$customjson = @$page->header()->add_json;
foreach ($microdata as $key => $value){


$jsonscript = PHP_EOL . '<script type="application/ld+json">' . PHP_EOL . json_encode($microdata[$key], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT ) . PHP_EOL . '</script>';
$outputjson = $outputjson . $jsonscript;
}

if(!empty($customjson)){
foreach($customjson as $json){
$buildjson = PHP_EOL . '<script type="application/ld+json">' . PHP_EOL . $json['custom_json'] . PHP_EOL . '</script>';
$outputcustomjson = $outputcustomjson . $buildjson ;
}
$outputjson = $outputjson . $outputcustomjson;
}


$outputjson = '</script>' . $outputjson . '<script>';
$this->grav['twig']->twig_vars['json'] = $outputjson;
$this->grav['twig']->twig_vars['myvar'] = $outputjson;
Expand Down

0 comments on commit 8c90aa4

Please sign in to comment.