new things hope this works

This commit is contained in:
Dan Chadwick 2024-04-20 15:13:53 -07:00
parent fb490112ad
commit dd99451666
16 changed files with 5478 additions and 310 deletions

View File

@ -32,8 +32,8 @@
"drupal/stage_file_proxy": "^2.1",
"drupal/views_json_source": "^2.0",
"drush/drush": "^12.4",
"symfony/css-selector": "^7.0",
"symfony/dom-crawler": "^7.0",
"symfony/css-selector": "^6",
"symfony/dom-crawler": "^6",
"symfony/polyfill-iconv": "1.28",
"symfony/polyfill-php80": "^1.29",
"symfony/polyfill-php81": "^1.29",
@ -112,5 +112,8 @@
" composer remove drupal/core-project-message"
]
}
},
"require-dev": {
"drupal/core-dev": "^10"
}
}

5301
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@ status: true
dependencies:
config:
- block_content.type.hero_slide
- field.field.block_content.hero_slide.field_external_video
- field.field.block_content.hero_slide.field_slide_image
- field.field.block_content.hero_slide.field_slide_link
- field.field.block_content.hero_slide.field_slide_text
@ -16,16 +17,24 @@ targetEntityType: block_content
bundle: hero_slide
mode: default
content:
field_external_video:
type: string_textfield
weight: 1
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_slide_image:
type: media_library_widget
weight: 26
weight: 2
region: content
settings:
media_types: { }
third_party_settings: { }
field_slide_link:
type: link_default
weight: 28
weight: 3
region: content
settings:
placeholder_url: ''
@ -33,18 +42,11 @@ content:
third_party_settings: { }
field_slide_text:
type: text_textarea
weight: 27
weight: 0
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
info:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
hidden: { }
hidden:
info: true

View File

@ -4,6 +4,7 @@ status: true
dependencies:
config:
- block_content.type.hero_slide
- field.field.block_content.hero_slide.field_external_video
- field.field.block_content.hero_slide.field_slide_image
- field.field.block_content.hero_slide.field_slide_link
- field.field.block_content.hero_slide.field_slide_text
@ -15,6 +16,14 @@ targetEntityType: block_content
bundle: hero_slide
mode: default
content:
field_external_video:
type: string
label: above
settings:
link_to_entity: false
third_party_settings: { }
weight: 3
region: content
field_slide_image:
type: entity_reference_entity_view
label: hidden

View File

@ -0,0 +1,19 @@
uuid: 6db81842-0403-4b92-bcea-b9e0f590c7b9
langcode: en
status: true
dependencies:
config:
- block_content.type.hero_slide
- field.storage.block_content.field_external_video
id: block_content.hero_slide.field_external_video
field_name: field_external_video
entity_type: block_content
bundle: hero_slide
label: 'External Video'
description: 'An externally hosted video.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string

View File

@ -0,0 +1,21 @@
uuid: 5c2255fb-5f8d-49ce-9206-d5348468cd7c
langcode: en
status: true
dependencies:
module:
- block_content
id: block_content.field_external_video
field_name: field_external_video
entity_type: block_content
type: string
settings:
max_length: 255
case_sensitive: false
is_ascii: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

View File

@ -28,7 +28,7 @@ class FighterImporter {
* Array of all fighters.
* @var array[]
*/
protected $fighters = [];
public $fighters = [];
/**
* The current weight class.
@ -160,9 +160,19 @@ public function loopThroughFighterPages($base_url): void {
// Here you are Dan.
// Implement caching to store instead of needing fresh requests.
for ($i=0; $i<=100; $i++) {
$ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15';
$headers = [
'referer' => true,
'verify' => false,
'headers' => [
'User-Agent' => 'DC SCRAPER/v1.0',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding' => 'gzip, deflate, br',
]
];
$url = $base_url . "&page=$i";
$cid = "ufc:" . $url;
$request = $this->httpClient->request('GET', $url, ['verify' => false]);
/* $cid = "ufc:" . $url; */
$request = $this->httpClient->request('GET', $url, $headers);
$content = $request->getBody()->getContents();
$check = strpos($content, "No Result Found For");
if (!$check) {
@ -174,6 +184,10 @@ public function loopThroughFighterPages($base_url): void {
}
}
public function quickTest($str) {
return "hello$str";
}
/**
* Extract fighters from an html string.
*/

View File

@ -0,0 +1,3 @@
<?php
return [];

View File

@ -0,0 +1,130 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\ufc\Kernel;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\ufc\Services\FightImporter
* @group ufc
*/
class WebScraperKernelTest extends UnitTestCase {
protected $fighterImporter;
public function setUp(): void {
parent::setUp();
$this->fighterImporter = $this->createMock('Drupal\ufc\Services\FighterImporter');
}
/**
* @dataProvider extractFighterNamesDataProvider
*/
public function testExtractFighterNames($test_input) {
$this->assertEquals("1", 2, "These do not match.");
}
private function extractFighterNamesDataProvider(): array {
return [
['
<ul class="l-flex--4col-1to4">
<li class="l-flex__item">
<div class="node node--type-athlete node--view-mode-all-athletes-result ds-1col clearfix">
<div class="c-listing-athlete-flipcard white">
<div class="c-listing-athlete-flipcard__inner">
<div class="c-listing-athlete-flipcard__front">
<div class="c-listing-athlete__thumbnail">
<div class="field field--name-image field--type-entity-reference field--label-hidden field__item">
<div class="layout layout--onecol">
<div class="layout__region layout__region--content">
<img src="https://dmxg5wxfqgb4u.cloudfront.net/styles/teaser/s3/2022-07/ABDELWAHAB_HAMDY_07-30.png?h=a30e7339&amp;itok=hQJx5TxB" width="400" height="300" loading="lazy" class="image-style-teaser">
</div>
</div>
</div>
</div>
<div class="c-listing-athlete__text">
<span class="c-listing-athlete__nickname">
<div class="field field--name-nickname field--type-string field--label-hidden">
<div class="field__item">"The Hammer"</div>
</div>
</span>
<span class="c-listing-athlete__name">
Hamdy Abdelwahab
</span>
<span class="c-listing-athlete__title">
<div class="field field--name-stats-weight-class field--type-entity-reference field--label-hidden field__items">
<div class="field__item">Heavyweight</div>
</div>
</span>
<span class="c-listing-athlete__record">5-0-0 (W-L-D)</span>
</div>
</div>
<div class="c-listing-athlete-flipcard__back">
<div class="c-listing-athlete__bgimg">
<div class="field field--name-image-body-right field--type-entity-reference field--label-hidden field__item">
<div class="layout layout--onecol">
<div class="layout__region layout__region--content">
<img src="https://dmxg5wxfqgb4u.cloudfront.net/styles/event_fight_card_upper_body_of_standing_athlete/s3/2022-07/ABDELWAHAB_HAMDY_R_07-30.png?itok=pAbtNV-r" width="185" height="580" loading="lazy" class="image-style-event-fight-card-upper-body-of-standing-athlete">
</div>
</div>
</div>
</div>
<div class="c-listing-athlete-flipcard__text__back">
<span class="c-listing-athlete__nickname">
<div class="field field--name-nickname field--type-string field--label-hidden">
<div class="field__item">"The Hammer"</div>
</div>
</span>
<span class="c-listing-athlete__name">
Hamdy Abdelwahab
</span>
</div>
<div class="c-listing-athlete-flipcard__action">
<a href="/athlete/hamdy-abdelwahab" class="e-button--black "><span class="e-button__text">
Athlete Profile
</span></a>
</div>
<div class="c-listing-athlete-flipcard__footer">
<h4>Follow</h4>
<ul class="c-listing-athlete-flipcard__social-menu">
<li class="c-listing-athlete-flipcard__social-item">
<a class="c-listing-athlete-flipcard__social-link" href="https://twitter.com/Hamdyabdelwah" target="_blank">
<span class="c-listing-athlete-flipcard__social-icon">
<span class="e-icon--small">
<svg class="e-icon__svg">
<title>Twitter</title>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/themes/custom/ufc/assets/svg/sprite-ui.svg#twitter"></use>
</svg>
</span>
</span>
</a>
</li>
<li class="c-listing-athlete-flipcard__social-item">
<a class="c-listing-athlete-flipcard__social-link" href="https://instagram.com/hamdy.abdelwahab1" target="_blank">
<span class="c-listing-athlete-flipcard__social-icon">
<span class="e-icon--small">
<svg class="e-icon__svg">
<title>Instagram</title>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/themes/custom/ufc/assets/svg/sprite-ui.svg#instagram"></use>
</svg>
</span>
</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</li>
</ul>
']
];
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\ufc\Unit;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\ufc\Services\FightImporter
* @group ufc
*/
class WebScraperTest extends UnitTestCase {
protected $fighterImporter;
public function setUp(): void {
parent::setUp();
$this->fighterImporter = $this->createMock('Drupal\ufc\Services\FighterImporter');
}
/**
* @dataProvider extractFighterNamesDataProvider
*/
public function testExtractFighterNames($test_input) {
$this->assertEquals("1", 2, "These do not match.");
}
}

View File

@ -28,11 +28,6 @@ header .navbar-nav a.nav-link:hover {
color: #f6c177;
}
main {
max-width: 1152px;
margin: auto;
}
#main {
z-index: 501;
}
@ -208,33 +203,27 @@ table.cols-5 td.incorrect {
color: white;
}
#block-dchadwick-homepagehero {
position: relative;
max-height: 400px;
}
#block-dchadwick-homepagehero .field--name-field-media-image {
max-height: 400px;
.hero-slide {
margin: 0 -0.5rem;
max-height: 500px;
overflow: hidden;
position: relative;
}
@media screen and (min-width: 1024px) {
#block-dchadwick-homepagehero .field--name-field-media-image img {
position: relative;
bottom: 100px;
}
.hero-slide video {
position: relative;
bottom: 100px;
}
#block-dchadwick-homepagehero #hero-caption {
.hero-caption {
width: auto;
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: -50px;
text-align: center;
min-width: 50%;
padding: 2rem;
padding-bottom: 1rem;
background: #31748f;
border-radius: 5px;
color: #f6c177;
top: 50%;
transform: translateY(-50%);
left: 2rem;
background: white;
padding: 2rem 8rem 2rem 2rem;
}
#footer {
text-align: center;
background: #c4a7e7;
@ -249,30 +238,17 @@ table.cols-5 td.incorrect {
margin: 0;
}
#recent-fights {
background: #fffaf3;
border: 2px solid #6e6a86;
}
#recent-fights > div {
grid-gap: 5px;
justify-content: center;
justify-content: space-evenly;
}
#block-dchadwick-recentfightsblock {
margin-top: 100px;
}
#block-dchadwick-recentfightsblock h2 {
background: #191724;
color: #f6c177;
padding: 1rem 0;
text-transform: uppercase;
font-size: 2.4rem;
text-align: center;
width: 100%;
border-left: 2px solid #6e6a86;
border-right: 2px solid #6e6a86;
border-top: 2px solid #6e6a86;
margin-bottom: 0;
margin: 50px 0;
}
@media screen and (min-width: 1024px) {
#block-dchadwick-recentfightsblock .card {

View File

@ -1,41 +1,21 @@
#block-dchadwick-homepagehero {
.hero-slide {
margin: 0 -0.5rem;
max-height: 500px;
overflow: hidden;
position: relative;
max-height: 400px;
.field--name-field-media-image {
max-height: 400px;
overflow: hidden;
img {
@media screen and (min-width: 1024px) {
position: relative;
bottom: 100px;
}
}
video {
position: relative;
bottom: 100px;
}
#hero-caption {
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: -50px;
text-align: center;
min-width: 50%;
padding: 2rem;
padding-bottom: 1rem;
background: $pine;
border-radius: 5px;
// border: 5px solid $pine;
color: $orangeish;
// opacity: 0.95;
}
#bgVideo {
}
}
.hero-caption {
width: auto;
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 2rem;
background: white;
padding: 2rem 8rem 2rem 2rem;
}

View File

@ -1,7 +1,8 @@
main {
max-width: $container-full;
margin: auto;
// max-width: $container-full;
// margin: auto;
}
#main {
#main {
z-index: 501;
}
}

View File

@ -1,30 +1,20 @@
#recent-fights {
background: $surface;
border: 2px solid $muted;
> div {
grid-gap: 5px;
justify-content: center;
justify-content: space-evenly;
}
}
#block-dchadwick-recentfightsblock {
margin-top: 100px;
h2 {
background: $base_bl;
color: $orangeish;
padding: 1rem 0;
text-transform: uppercase;
font-size: 2.4rem;
text-align: center;
width: 100%;
border-left: 2px solid $muted;
border-right: 2px solid $muted;
border-top: 2px solid $muted;
margin-bottom: 0;
margin: 50px 0;
}
.card {

View File

@ -31,19 +31,41 @@
'block',
'block-' ~ configuration.provider|clean_class,
'block-' ~ plugin_id|clean_class,
'hero-slide',
'container-fliud',
]
%}
{# Set the variables for the block #}
{% set hasRemoteVideo = content.field_external_video.0['#context']['value'] %}
{% set slideImage = content.field_slide_image.0['#media'].field_media_image.entity.uri.value %}
<div{{ attributes.addClass(classes) }}>
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes }}>{{ label }}</h2>
{% endif %}
{{ title_suffix }}
{% block content %}
<div id="hero-image">{{ content.field_slide_image }}</div>
<div id="hero-caption">
<h2>{{ content.field_slide_text }}</h2>
<p>{{ content.field_slide_link }}</p>
{{ title_prefix }}
{{ title_suffix }}
<div class="hero-bground">
{% if hasRemoteVideo is not null %}
<video autoplay muted loop id="bgVideo">
<source src="{{ hasRemoteVideo }}" type="video/mp4">
</video>
{% else %}
<img src="{{ slideImage }}">
{% endif %}
</div>
<div class="hero-caption">
<div class="hero-caption__text">
{{ content.field_slide_text }}
</div>
<div class="hero-caption__button">
{{ content.field_slide_link }}
</div>
</div>
{% endblock %}
</div>

View File

@ -1,47 +0,0 @@
{#
/**
* @file
* Theme override to display a block.
*
* Available variables:
* - plugin_id: The ID of the block implementation.
* - label: The configured label of the block if visible.
* - configuration: A list of the block's configuration values.
* - label: The configured label for the block.
* - label_display: The display settings for the label.
* - provider: The module or other provider that provided this block plugin.
* - Block plugin specific settings will also be stored here.
* - in_preview: Whether the plugin is being rendered in preview mode.
* - content: The content of this block.
* - attributes: array of HTML attributes populated by modules, intended to
* be added to the main container tag of this template.
* - id: A valid HTML ID and guaranteed unique.
* - title_attributes: Same as attributes, except applied to the main title
* tag that appears in the template.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the main title tag that appears in the template.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the main title tag that appears in the template.
*
* @see template_preprocess_block()
*/
#}
{%
set classes = [
'block',
'block-' ~ configuration.provider|clean_class,
'block-' ~ plugin_id|clean_class,
'hero-block',
]
%}
<div{{ attributes.addClass(classes) }}>
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes }}>{{ label }}</h2>
{% endif %}
{{ title_suffix }}
{% block content %}
{{ dump(content) }}
{{ content }}
{% endblock %}
</div>