Skip to content

Commit

Permalink
adding brand context
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarholt committed Sep 16, 2024
1 parent 5e6c6f8 commit f2b88b3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
8 changes: 6 additions & 2 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
Name: Silverstripe SEO AI config
Name: Silverstripe SEO AI Configuration
---

Page:
extensions:
- PlasticStudio\SEOAI\Extensions\SeoAIExtension
- PlasticStudio\SEOAI\Extensions\SeoAIExtension

SilverStripe\SiteConfig\SiteConfig:
extensions:
- PlasticStudio\SEOAI\Extensions\SeoAISiteConfigExtension
12 changes: 11 additions & 1 deletion src/Extensions/SeoAIExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\SiteConfig\SiteConfig;

class SeoAIExtension extends DataExtension
{
Expand All @@ -15,7 +16,7 @@ class SeoAIExtension extends DataExtension

public function updateSettingsFields(FieldList $fields)
{
$fields->addFieldToTab('Root.MetaTags', CheckboxField::create('GenerateTags', 'Re-generate meta tags')->setDescription('This may take several seconds.'), 'MetaTitle');
$fields->addFieldToTab('Root.MetaTags', CheckboxField::create('GenerateTags', 'Re-generate meta tags')->setDescription('Check this box before publishing to re-generate the meta-tags. This may take several seconds.'), 'MetaTitle');
}

public function onAfterWrite()
Expand Down Expand Up @@ -48,6 +49,9 @@ public function generatePrompt()
// Get the content for the current page
$pageLink = $this->owner->AbsoluteLink();

// Get brand context
$brandContext = SiteConfig::current_site_config()->ContextPrompt;

// Strip the content of header, footer and nav elements
$domParser = HtmlDomParser::str_get_html(file_get_contents($pageLink));

Expand Down Expand Up @@ -80,6 +84,12 @@ public function generatePrompt()
"metaDescription": "This is an example of the meta description."
}
Here is some background information on the brand which the web page belongs to, delimited by ---:
---
$brandContext
---
Here is the content for you to generate meta-tags for, deliniated by ~:
~
Expand Down
19 changes: 19 additions & 0 deletions src/Extensions/SeoAISiteConfigExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace PlasticStudio\SEOAI\Extensions;

use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Forms\TextareaField;

class SeoAISiteConfigExtension extends DataExtension
{
private static $db = [
'ContextPrompt' => 'Varchar(255)',
];

public function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab('Root.SEO', TextareaField::create('ContextPrompt', 'Brand Context Prompt')->setDescription('Additional information to give AI about your brand / content for more accurate metadata generation'), 'UseTitleAsMetaTitle');
}
}

0 comments on commit f2b88b3

Please sign in to comment.