mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-21 15:54:57 +00:00
Compare commits
2 Commits
@rocket/el
...
@rocket/cl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6c564ede2 | ||
|
|
a498a5da44 |
@@ -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