mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-21 15:54:57 +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
|
||||
|
||||
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
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- eb74110: Add info about how many files and links will be checked
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 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/).
|
||||
|
||||
## 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)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "check-html-links",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
|
||||
@@ -13,7 +13,17 @@ async function main() {
|
||||
|
||||
console.log('👀 Checking if all internal links work...');
|
||||
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);
|
||||
if (errors.length > 0) {
|
||||
let referenceCount = 0;
|
||||
|
||||
@@ -267,13 +267,15 @@ export async function validateFiles(files, rootDir) {
|
||||
errors = [];
|
||||
checkLocalFiles = [];
|
||||
idCache = new Map();
|
||||
let numberLinks = 0;
|
||||
for (const htmlFilePath of files) {
|
||||
const { links } = await extractReferences(htmlFilePath);
|
||||
numberLinks += links.length;
|
||||
await resolveLinks(links, { htmlFilePath, rootDir });
|
||||
}
|
||||
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) {
|
||||
const rootDir = path.resolve(inRootDir);
|
||||
const files = await listFiles('**/*.html', rootDir);
|
||||
const errors = await validateFiles(files, rootDir);
|
||||
const { errors } = await validateFiles(files, rootDir);
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @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
|
||||
|
||||
### Minor Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@rocket/cli",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
|
||||
@@ -39,22 +39,25 @@ const templateEndings = [
|
||||
'.pug',
|
||||
];
|
||||
|
||||
function endsWithAny(string, suffixes) {
|
||||
for (let suffix of suffixes) {
|
||||
if (string.endsWith(suffix)) {
|
||||
function isTemplateFile(href) {
|
||||
for (const templateEnding of templateEndings) {
|
||||
if (href.endsWith(templateEnding)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isTemplateFile(href) {
|
||||
return endsWithAny(href, templateEndings);
|
||||
}
|
||||
|
||||
function isIndexTemplateFile(href) {
|
||||
const hrefParsed = path.parse(href);
|
||||
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 };
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
const newHrefs = [];
|
||||
for (const hrefObj of hrefs) {
|
||||
const newHrefObj = { ...hrefObj };
|
||||
const [href, anchor] = newHrefObj.value.split('#');
|
||||
const suffix = anchor ? `#${anchor}` : '';
|
||||
const { value: href, suffix } = getValueAndAnchor(hrefObj.value);
|
||||
|
||||
if (isRelativeLink(href) && isTemplateFile(href)) {
|
||||
const hrefParsed = path.parse(href);
|
||||
|
||||
@@ -353,7 +353,7 @@ describe('RocketCli e2e', () => {
|
||||
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');
|
||||
|
||||
const namedMdContent = [
|
||||
@@ -415,6 +415,7 @@ describe('RocketCli e2e', () => {
|
||||
'<a href="guides/#with-anchor">Guides</a>',
|
||||
'<a href="./one-level/raw/">Raw</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="absolute-img"></p>',
|
||||
'<div>',
|
||||
@@ -422,6 +423,7 @@ describe('RocketCli e2e', () => {
|
||||
' <a href="guides/#with-anchor">Guides</a>',
|
||||
' <a href="./one-level/raw/">Raw</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="absolute-img">',
|
||||
' <picture>',
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
[Guides](./guides.md#with-anchor)
|
||||
[Raw](./one-level/raw.html)
|
||||
[Template](./template.njk)
|
||||
[EndingIndex](./rules/tabindex.md)
|
||||

|
||||

|
||||
|
||||
@@ -10,6 +11,7 @@
|
||||
<a href="./guides.md#with-anchor">Guides</a>
|
||||
<a href="./one-level/raw.html">Raw</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="absolute-img">
|
||||
<picture>
|
||||
|
||||
Reference in New Issue
Block a user