Skip to content

Commit

Permalink
[TASK] Do not add type if html5 doctype (#81)
Browse files Browse the repository at this point in the history
* [TASK] Setup local environment

* [TASK] Do not add type if html5 doctype

Resolves: #80
  • Loading branch information
sabbelasichon authored Apr 6, 2021
1 parent 27283af commit f8d1c92
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on: [ push, pull_request ]
jobs:
php-lint:
name: "PHP linter"
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
strategy:
matrix:
php-versions: [ 7.4 ]
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
/.Build
/.php_cs.cache
/composer.lock
/Resources/Public/Private
/Resources/Public/Build
/Resources/Private/Templates/Page.html
/Resources/Private/Php/Libraries/vendor
/phpunit.xml
/var
.phpunit.result.cache
.ddev/
config
assets
webpack.config.js
node_modules
package.json
yarn.lock
25 changes: 25 additions & 0 deletions Classes/Asset/TagRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function renderWebpackScriptTags(string $entryName, string $position = se
'crossorigin' => '',
], $parameters);

if ($this->removeType($parameters)) {
unset($attributes['type']);
}

$attributes = array_values($attributes);

$pageRendererMethodName = 'addJS' . ($position === self::POSITION_FOOTER ? 'Footer' : '');
Expand Down Expand Up @@ -160,4 +164,25 @@ private function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}

private function removeType(array $parameters): bool
{
if (array_key_exists('type', $parameters)) {
return false;
}

if ($this->applicationType === null) {
return false;
}

if (!$this->applicationType->isFrontend()) {
return false;
}

if ($this->getTypoScriptFrontendController()->config['config']['doctype'] !== 'html5') {
return false;
}

return true;
}
}
4 changes: 2 additions & 2 deletions Configuration/TypoScript/constants.typoscript
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugin.tx_typo3encore {
settings {
entrypointJsonPath = EXT:typo3_encore/Resources/Public/entrypoints.json
manifestJsonPath = EXT:typo3_encore/Resources/Public/manifest.json
entrypointJsonPath = EXT:typo3_encore/Resources/Public/Build/entrypoints.json
manifestJsonPath = EXT:typo3_encore/Resources/Public/Build/manifest.json

# Throw an exception if the entrypoints.json file is missing or an entry is missing from the data
strictMode = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import 'EXT:typo3_encore/Configuration/TypoScript/setup.typoscript'
@import './MainRenderer.typoscript'

config.doctype = html5
18 changes: 18 additions & 0 deletions Tests/Functional/IncludeFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ public function addFilesWithAbsRefPrefix(): void
self::assertStringContainsString('sha384-ysKW+jP4sNH9UfX9+fqN4iC/RB3L9jmWUd8ABJrBbAHFwL6wNmvNT5x178Fx6Xh0', $content);
}

/**
* @test
*/
public function addFilesWithHtml5DocType(): void
{
$this->setUpFrontendRootPage(
self::ROOT_PAGE_UID,
[
'EXT:typo3_encore/Tests/Functional/Fixtures/Frontend/MainRendererHtml5.typoscript',
]
);
$this->setUpSites(self::ROOT_PAGE_UID, []);
$response = $this->executeFrontendRequest((new InternalRequest())->withPageId(self::ROOT_PAGE_UID));

$content = $response->getBody()->__toString();
self::assertStringNotContainsString('text/javascript', $content);
}

protected function setUpSites(int $pageId, array $sites): void
{
if (empty($sites[$pageId])) {
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"typo3/cms-core": "^10.4.2 || ^11.0",
"symfony/web-link": "^4.3",
"symfony/asset": "^5.0",
"ext-dom": "*"
"ext-dom": "*",
"typo3/cms-tstemplate": "^10.4.2 || ^11.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
Expand Down

0 comments on commit f8d1c92

Please sign in to comment.