mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-22 00:41:21 +00:00
Compare commits
6 Commits
@rocket/cl
...
check-html
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45cd7206f1 | ||
|
|
eb74110dd8 | ||
|
|
517c7780ab | ||
|
|
e4852db673 | ||
|
|
c6c564ede2 | ||
|
|
a498a5da44 |
@@ -1,7 +1,106 @@
|
|||||||
# Presets >> Create your own || 90
|
# Presets >> Create your own || 90
|
||||||
|
|
||||||
All loaded presets will be combined but you can override each file.
|
A preset is setup function and a folder including `_assets`, `_data` and `_includes` (all optional).
|
||||||
|
|
||||||
Take a look at `docs/_merged_includes` and override what you want to override by placing the same filename into `_includes`.
|
To play around with a preset you can create a folder `fire-theme`.
|
||||||
|
|
||||||
Also works for `_assets`, `_data` ...
|
You then create the setup function for it with only one property called `path` which will allow Rocket to properly resolve it.
|
||||||
|
|
||||||
|
## Create a Preset Config File
|
||||||
|
|
||||||
|
👉 `fire-theme/fireTheme.js`
|
||||||
|
|
||||||
|
```js
|
||||||
|
import path from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
export function fireTheme() {
|
||||||
|
return {
|
||||||
|
path: path.resolve(__dirname),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Once you have that you can start filling in content you need.
|
||||||
|
|
||||||
|
For example a we could override the full `layout.css` by adding a it like so
|
||||||
|
|
||||||
|
👉 `fire-theme/layout.css`
|
||||||
|
|
||||||
|
```css
|
||||||
|
body {
|
||||||
|
background: hotpink;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Once you have that you can add it to your Rocket Config.
|
||||||
|
|
||||||
|
NOTE: The order of presets is important, as for example in this case we take everything from `rocketLaunch` but later override via `fireTheme`.
|
||||||
|
|
||||||
|
👉 `rocket-config.js`
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { rocketLaunch } from '@rocket/launch';
|
||||||
|
import { fireTheme } from 'path/to/fire-theme/fireTheme.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
presets: [rocketLaunch(), fireTheme()],
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
## Publish a preset
|
||||||
|
|
||||||
|
If you would like to publish a preset to use it on multiple websites or share it with your friends you can do like so.
|
||||||
|
|
||||||
|
1. Pick a name for the package => for this example we take `fire-theme`.
|
||||||
|
2. Create a new folder `fire-theme`
|
||||||
|
3. Create a folder `fire-theme/preset` copy `fireTheme.js` from [above](#create-a-preset-config-file) into `preset/fireTheme.js`
|
||||||
|
4. Add a 👉 `package.json`
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "fire-theme",
|
||||||
|
"version": "0.3.0",
|
||||||
|
"description": "Fire Theme for Rocket",
|
||||||
|
"license": "MIT",
|
||||||
|
"type": "module",
|
||||||
|
"exports": {
|
||||||
|
".": "./index.js",
|
||||||
|
"./preset/": "./preset/"
|
||||||
|
},
|
||||||
|
"files": ["*.js", "preset"],
|
||||||
|
"keywords": ["rocket", "preset"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Add a 👉 `index.js`
|
||||||
|
|
||||||
|
```js
|
||||||
|
export { fireTheme } from './preset/fireTheme.js';
|
||||||
|
```
|
||||||
|
|
||||||
|
6. Add a 👉 `README.md`
|
||||||
|
|
||||||
|
````
|
||||||
|
# FireTheme
|
||||||
|
|
||||||
|
This is a theme/preset for [Rocket](https://rocket.modern-web.dev/).
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
npm i -D fire-theme
|
||||||
|
```
|
||||||
|
|
||||||
|
Add it to your 👉 `rocket.config.js`
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { fireTheme } from 'fire-theme';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
presets: [fireTheme()],
|
||||||
|
};
|
||||||
|
```
|
||||||
|
````
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
# check-html-links
|
# check-html-links
|
||||||
|
|
||||||
|
## 0.1.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- eb74110: Add info about how many files and links will be checked
|
||||||
|
|
||||||
## 0.1.0
|
## 0.1.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|
||||||
- cd22231: Initial release
|
- cd22231: Initial release
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ npx check-html-links _site
|
|||||||
|
|
||||||
For docs please see our homepage [https://rocket.modern-web.dev/docs/tools/check-html-links/](https://rocket.modern-web.dev/docs/tools/check-html-links/).
|
For docs please see our homepage [https://rocket.modern-web.dev/docs/tools/check-html-links/](https://rocket.modern-web.dev/docs/tools/check-html-links/).
|
||||||
|
|
||||||
## Comparision
|
## Comparison
|
||||||
|
|
||||||
Checking the output of [11ty-website](https://github.com/11ty/11ty-website) with 13 missing reference targets (used by 516 links) while checking 501 files. (on January 17, 2021)
|
Checking the output of [11ty-website](https://github.com/11ty/11ty-website) with 13 missing reference targets (used by 516 links) while checking 501 files. (on January 17, 2021)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "check-html-links",
|
"name": "check-html-links",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13,7 +13,17 @@ async function main() {
|
|||||||
|
|
||||||
console.log('👀 Checking if all internal links work...');
|
console.log('👀 Checking if all internal links work...');
|
||||||
const files = await listFiles('**/*.html', rootDir);
|
const files = await listFiles('**/*.html', rootDir);
|
||||||
const errors = await validateFiles(files, rootDir);
|
|
||||||
|
const filesOutput =
|
||||||
|
files.length == 0
|
||||||
|
? '🧐 No files to check. Did you select the correct folder?'
|
||||||
|
: `🔥 Found a total of ${chalk.green.bold(files.length)} files to check!`;
|
||||||
|
console.log(filesOutput);
|
||||||
|
|
||||||
|
const { errors, numberLinks } = await validateFiles(files, rootDir);
|
||||||
|
|
||||||
|
console.log(`🔗 Found a total of ${chalk.green.bold(numberLinks)} links to validate!\n`);
|
||||||
|
|
||||||
const performance = process.hrtime(performanceStart);
|
const performance = process.hrtime(performanceStart);
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
let referenceCount = 0;
|
let referenceCount = 0;
|
||||||
|
|||||||
@@ -267,13 +267,15 @@ export async function validateFiles(files, rootDir) {
|
|||||||
errors = [];
|
errors = [];
|
||||||
checkLocalFiles = [];
|
checkLocalFiles = [];
|
||||||
idCache = new Map();
|
idCache = new Map();
|
||||||
|
let numberLinks = 0;
|
||||||
for (const htmlFilePath of files) {
|
for (const htmlFilePath of files) {
|
||||||
const { links } = await extractReferences(htmlFilePath);
|
const { links } = await extractReferences(htmlFilePath);
|
||||||
|
numberLinks += links.length;
|
||||||
await resolveLinks(links, { htmlFilePath, rootDir });
|
await resolveLinks(links, { htmlFilePath, rootDir });
|
||||||
}
|
}
|
||||||
await validateLocalFiles(checkLocalFiles);
|
await validateLocalFiles(checkLocalFiles);
|
||||||
|
|
||||||
return errors;
|
return { errors: errors, numberLinks: numberLinks };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -282,6 +284,6 @@ export async function validateFiles(files, rootDir) {
|
|||||||
export async function validateFolder(inRootDir) {
|
export async function validateFolder(inRootDir) {
|
||||||
const rootDir = path.resolve(inRootDir);
|
const rootDir = path.resolve(inRootDir);
|
||||||
const files = await listFiles('**/*.html', rootDir);
|
const files = await listFiles('**/*.html', rootDir);
|
||||||
const errors = await validateFiles(files, rootDir);
|
const { errors } = await validateFiles(files, rootDir);
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @rocket/cli
|
# @rocket/cli
|
||||||
|
|
||||||
|
## 0.3.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- a498a5d: Make sure links to `*index.md` files are not treated as folder index files like `index.md`
|
||||||
|
|
||||||
## 0.3.0
|
## 0.3.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rocket/cli",
|
"name": "@rocket/cli",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -39,22 +39,25 @@ const templateEndings = [
|
|||||||
'.pug',
|
'.pug',
|
||||||
];
|
];
|
||||||
|
|
||||||
function endsWithAny(string, suffixes) {
|
function isTemplateFile(href) {
|
||||||
for (let suffix of suffixes) {
|
for (const templateEnding of templateEndings) {
|
||||||
if (string.endsWith(suffix)) {
|
if (href.endsWith(templateEnding)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isTemplateFile(href) {
|
|
||||||
return endsWithAny(href, templateEndings);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isIndexTemplateFile(href) {
|
function isIndexTemplateFile(href) {
|
||||||
|
const hrefParsed = path.parse(href);
|
||||||
const indexTemplateEndings = templateEndings.map(ending => `index${ending}`);
|
const indexTemplateEndings = templateEndings.map(ending => `index${ending}`);
|
||||||
return endsWithAny(href, indexTemplateEndings);
|
|
||||||
|
for (const indexTemplateEnding of indexTemplateEndings) {
|
||||||
|
if (hrefParsed.base === indexTemplateEnding) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,12 +94,46 @@ function extractReferences(html, inputPath) {
|
|||||||
return { hrefs, assets };
|
return { hrefs, assets };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} inValue
|
||||||
|
*/
|
||||||
|
function getValueAndAnchor(inValue) {
|
||||||
|
let value = inValue.replace(/&#/g, '--__check-html-links__--');
|
||||||
|
let anchor = '';
|
||||||
|
let suffix = '';
|
||||||
|
|
||||||
|
if (value.includes('#')) {
|
||||||
|
[value, anchor] = value.split('#');
|
||||||
|
suffix = `#${anchor}`;
|
||||||
|
}
|
||||||
|
if (value.includes('?')) {
|
||||||
|
value = value.split('?')[0];
|
||||||
|
}
|
||||||
|
if (anchor.includes(':~:')) {
|
||||||
|
anchor = anchor.split(':~:')[0];
|
||||||
|
}
|
||||||
|
if (value.includes(':~:')) {
|
||||||
|
value = value.split(':~:')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
value = value.replace(/--__check-html-links__--/g, '&#');
|
||||||
|
anchor = anchor.replace(/--__check-html-links__--/g, '&#');
|
||||||
|
suffix = suffix.replace(/--__check-html-links__--/g, '&#');
|
||||||
|
value = value.trim();
|
||||||
|
anchor = anchor.trim();
|
||||||
|
|
||||||
|
return {
|
||||||
|
value,
|
||||||
|
anchor,
|
||||||
|
suffix,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function calculateNewHrefs(hrefs, inputPath) {
|
function calculateNewHrefs(hrefs, inputPath) {
|
||||||
const newHrefs = [];
|
const newHrefs = [];
|
||||||
for (const hrefObj of hrefs) {
|
for (const hrefObj of hrefs) {
|
||||||
const newHrefObj = { ...hrefObj };
|
const newHrefObj = { ...hrefObj };
|
||||||
const [href, anchor] = newHrefObj.value.split('#');
|
const { value: href, suffix } = getValueAndAnchor(hrefObj.value);
|
||||||
const suffix = anchor ? `#${anchor}` : '';
|
|
||||||
|
|
||||||
if (isRelativeLink(href) && isTemplateFile(href)) {
|
if (isRelativeLink(href) && isTemplateFile(href)) {
|
||||||
const hrefParsed = path.parse(href);
|
const hrefParsed = path.parse(href);
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ describe('RocketCli e2e', () => {
|
|||||||
expect(guidesHtml).to.equal('/_merged_assets/11ty-img/58b7e437-1200.png');
|
expect(guidesHtml).to.equal('/_merged_assets/11ty-img/58b7e437-1200.png');
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('will add "../" for links and image urls only within named template files', async () => {
|
it('will add "../" for links and image urls only within named template files', async () => {
|
||||||
await executeStart('e2e-fixtures/image-link/rocket.config.js');
|
await executeStart('e2e-fixtures/image-link/rocket.config.js');
|
||||||
|
|
||||||
const namedMdContent = [
|
const namedMdContent = [
|
||||||
@@ -415,6 +415,7 @@ describe('RocketCli e2e', () => {
|
|||||||
'<a href="guides/#with-anchor">Guides</a>',
|
'<a href="guides/#with-anchor">Guides</a>',
|
||||||
'<a href="./one-level/raw/">Raw</a>',
|
'<a href="./one-level/raw/">Raw</a>',
|
||||||
'<a href="template/">Template</a>',
|
'<a href="template/">Template</a>',
|
||||||
|
'<a href="./rules/tabindex/">EndingIndex</a>',
|
||||||
'<img src="./images/my-img.svg" alt="my-img">',
|
'<img src="./images/my-img.svg" alt="my-img">',
|
||||||
'<img src="/images/my-img.svg" alt="absolute-img"></p>',
|
'<img src="/images/my-img.svg" alt="absolute-img"></p>',
|
||||||
'<div>',
|
'<div>',
|
||||||
@@ -422,6 +423,7 @@ describe('RocketCli e2e', () => {
|
|||||||
' <a href="guides/#with-anchor">Guides</a>',
|
' <a href="guides/#with-anchor">Guides</a>',
|
||||||
' <a href="./one-level/raw/">Raw</a>',
|
' <a href="./one-level/raw/">Raw</a>',
|
||||||
' <a href="template/">Template</a>',
|
' <a href="template/">Template</a>',
|
||||||
|
' <a href="./rules/tabindex/">EndingIndex</a>',
|
||||||
' <img src="./images/my-img.svg" alt="my-img">',
|
' <img src="./images/my-img.svg" alt="my-img">',
|
||||||
' <img src="/images/my-img.svg" alt="absolute-img">',
|
' <img src="/images/my-img.svg" alt="absolute-img">',
|
||||||
' <picture>',
|
' <picture>',
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
[Guides](./guides.md#with-anchor)
|
[Guides](./guides.md#with-anchor)
|
||||||
[Raw](./one-level/raw.html)
|
[Raw](./one-level/raw.html)
|
||||||
[Template](./template.njk)
|
[Template](./template.njk)
|
||||||
|
[EndingIndex](./rules/tabindex.md)
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
@@ -10,6 +11,7 @@
|
|||||||
<a href="./guides.md#with-anchor">Guides</a>
|
<a href="./guides.md#with-anchor">Guides</a>
|
||||||
<a href="./one-level/raw.html">Raw</a>
|
<a href="./one-level/raw.html">Raw</a>
|
||||||
<a href="./template.njk">Template</a>
|
<a href="./template.njk">Template</a>
|
||||||
|
<a href="./rules/tabindex.md">EndingIndex</a>
|
||||||
<img src="./images/my-img.svg" alt="my-img">
|
<img src="./images/my-img.svg" alt="my-img">
|
||||||
<img src="/images/my-img.svg" alt="absolute-img">
|
<img src="/images/my-img.svg" alt="absolute-img">
|
||||||
<picture>
|
<picture>
|
||||||
|
|||||||
Reference in New Issue
Block a user