mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
fix: link tag missing type="application/rss+xml"
This commit is contained in:
parent
fc63748222
commit
9654a8c00b
@ -222,13 +222,20 @@ if (! function_exists('link_tag')) {
|
|||||||
/**
|
/**
|
||||||
* Link
|
* Link
|
||||||
*
|
*
|
||||||
* Generates link to a CSS file
|
* Generates link tag
|
||||||
*
|
*
|
||||||
* @param array|string $href Stylesheet href or an array
|
* @param array<string, bool|string>|string $href Stylesheet href or an array
|
||||||
* @param bool $indexPage should indexPage be added to the CSS path.
|
* @param bool $indexPage should indexPage be added to the CSS path.
|
||||||
*/
|
*/
|
||||||
function link_tag($href = '', string $rel = 'stylesheet', string $type = 'text/css', string $title = '', string $media = '', bool $indexPage = false, string $hreflang = ''): string
|
function link_tag(
|
||||||
{
|
$href = '',
|
||||||
|
string $rel = 'stylesheet',
|
||||||
|
string $type = 'text/css',
|
||||||
|
string $title = '',
|
||||||
|
string $media = '',
|
||||||
|
bool $indexPage = false,
|
||||||
|
string $hreflang = ''
|
||||||
|
): string {
|
||||||
$link = '<link ';
|
$link = '<link ';
|
||||||
|
|
||||||
// extract fields if needed
|
// extract fields if needed
|
||||||
@ -258,7 +265,7 @@ if (! function_exists('link_tag')) {
|
|||||||
|
|
||||||
$link .= 'rel="' . $rel . '" ';
|
$link .= 'rel="' . $rel . '" ';
|
||||||
|
|
||||||
if (! in_array($rel, ['alternate', 'canonical'], true)) {
|
if ($type !== '' && $rel !== 'canonical') {
|
||||||
$link .= 'type="' . $type . '" ';
|
$link .= 'type="' . $type . '" ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,6 +319,44 @@ final class HTMLHelperTest extends CIUnitTestCase
|
|||||||
$this->assertSame($expected, link_tag($target, 'banana', 'fruit', 'Go away', 'VHS'));
|
$this->assertSame($expected, link_tag($target, 'banana', 'fruit', 'Go away', 'VHS'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLinkTagFavicon()
|
||||||
|
{
|
||||||
|
$tag = link_tag('favicon.ico', 'shortcut icon', 'image/ico');
|
||||||
|
|
||||||
|
$expected = '<link href="http://example.com/favicon.ico" rel="shortcut icon" type="image/ico" />';
|
||||||
|
$this->assertSame($expected, $tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLinkTagRss()
|
||||||
|
{
|
||||||
|
$tag = link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');
|
||||||
|
|
||||||
|
$expected = '<link href="http://example.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" />';
|
||||||
|
$this->assertSame($expected, $tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLinkTagAlternate()
|
||||||
|
{
|
||||||
|
$tag = link_tag(
|
||||||
|
'http://sp.example.com/',
|
||||||
|
'alternate',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'only screen and (max-width: 640px)'
|
||||||
|
);
|
||||||
|
|
||||||
|
$expected = '<link href="http://sp.example.com/" rel="alternate" media="only screen and (max-width: 640px)" />';
|
||||||
|
$this->assertSame($expected, $tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLinkTagCanonical()
|
||||||
|
{
|
||||||
|
$tag = link_tag('http://www.example.com/', 'canonical');
|
||||||
|
|
||||||
|
$expected = '<link href="http://www.example.com/" rel="canonical" />';
|
||||||
|
$this->assertSame($expected, $tag);
|
||||||
|
}
|
||||||
|
|
||||||
public function testLinkTagArray()
|
public function testLinkTagArray()
|
||||||
{
|
{
|
||||||
$parms = [
|
$parms = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user