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