Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Type attribute to Link of CSS #173

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ const checkMetadata = (
if (typeof options.style === 'string') {
metadata.link.push([
{ name: 'rel', value: 'stylesheet' },
{ name: 'type', value: 'text/css' },
{ name: 'href', value: options.style },
]);
} else if (Array.isArray(options.style)) {
for (const style of options.style) {
metadata.link.push([
{ name: 'rel', value: 'stylesheet' },
{ name: 'type', value: 'text/css' },
{ name: 'href', value: style },
]);
}
Expand Down
34 changes: 22 additions & 12 deletions tests/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ meta:
content: 'darkred'
link:
- rel: 'stylesheet'
type: 'text/css'
href: 'sample1.css'
- rel: 'stylesheet'
type: 'text/css'
href: 'sample2.css'
script:
- type: 'text/javascript'
Expand Down Expand Up @@ -95,10 +97,12 @@ other-meta2: 'other2'
link: [
[
{ name: 'rel', value: 'stylesheet' },
{ name: 'type', value: 'text/css' },
{ name: 'href', value: 'sample1.css' },
],
[
{ name: 'rel', value: 'stylesheet' },
{ name: 'type', value: 'text/css'},
{ name: 'href', value: 'sample2.css' },
],
],
Expand Down Expand Up @@ -172,8 +176,10 @@ meta:
content: 'darkred'
link:
- rel: 'stylesheet'
type: 'text/css'
href: 'sample1.css'
- rel: 'stylesheet'
type: 'text/css'
href: 'sample2.css'
script:
- type: 'text/javascript'
Expand All @@ -200,8 +206,8 @@ Text
<meta name="theme-color" media="(prefers-color-scheme: light)" content="red">
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="darkred">
<meta name="author" content="Author">
<link rel="stylesheet" href="sample1.css">
<link rel="stylesheet" href="sample2.css">
<link rel="stylesheet" type="text/css" href="sample1.css">
<link rel="stylesheet" type="text/css" href="sample2.css">
<script type="text/javascript" src="sample1.js"></script>
<script type="text/javascript" src="sample2.js"></script>
</head>
Expand Down Expand Up @@ -239,8 +245,10 @@ meta:
content:
link:
- rel:
type:
href:
- rel:
type:
href:
script:
- type:
Expand All @@ -264,8 +272,8 @@ Text
<meta name="" media="" content="">
<meta name="" media="" content="">
<meta name="author" content="">
<link rel="" href="">
<link rel="" href="">
<link rel="" type="" href="">
<link rel="" type="" href="">
<script type="" src=""></script>
<script type="" src=""></script>
</head>
Expand Down Expand Up @@ -302,6 +310,7 @@ it('Style from options', () => {
const md = `---
link:
- rel: 'stylesheet'
type: 'text/css'
href: 'sample1.css'
---
`;
Expand All @@ -311,8 +320,8 @@ link:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="sample1.css">
<link rel="stylesheet" href="sample2.css">
<link rel="stylesheet" type="text/css" href="sample1.css">
<link rel="stylesheet" type="text/css" href="sample2.css">
</head>
<body></body>
</html>
Expand All @@ -328,7 +337,7 @@ it('Styles from options (String)', () => {
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="sample.css">
<link rel="stylesheet" type="text/css" href="sample.css">
</head>
<body></body>
</html>
Expand All @@ -344,8 +353,8 @@ it('Styles from options (String[])', () => {
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="sample1.css">
<link rel="stylesheet" href="sample2.css">
<link rel="stylesheet" type="text/css" href="sample1.css">
<link rel="stylesheet" type="text/css" href="sample2.css">
</head>
<body></body>
</html>
Expand All @@ -357,6 +366,7 @@ it('Styles from options with frontmatter', () => {
const md = `---
link:
- rel: 'stylesheet'
type: 'text/css'
href: 'sample1.css'
---
`;
Expand All @@ -366,9 +376,9 @@ link:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="sample1.css">
<link rel="stylesheet" href="sample2.css">
<link rel="stylesheet" href="sample3.css">
<link rel="stylesheet" type="text/css" href="sample1.css">
<link rel="stylesheet" type="text/css" href="sample2.css">
<link rel="stylesheet" type="text/css" href="sample3.css">
</head>
<body></body>
</html>
Expand Down
Loading