Skip to content

Commit

Permalink
Merge pull request #22 from kmlbgn/master
Browse files Browse the repository at this point in the history
fix: add check for skipping image links parsing in InternalLinkPlugin
  • Loading branch information
kmlbgn authored Jan 4, 2024
2 parents 0b906bc + b88a2ab commit bfbc5c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"// test out with a private sample notion db": "",
"pull": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE --log-level verbose",
"pulldoc": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE_DOC --log-level verbose -y",
"pulldoc2": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE_DOC -m ./docs -i ./static/notion_imgs -p /notion_imgs/ --yes --log-level verbose",
"large-site-test": "npm run ts -- -n $SIL_BLOOM_DOCS_NOTION_TOKEN -r $SIL_BLOOM_DOCS_NOTION_ROOT_PAGE --locales en,fr --log-level debug",
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
"pull-test-css": "npm run ts -- --css-output-directory ./test/css -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
Expand Down
13 changes: 11 additions & 2 deletions src/plugins/internalLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { error, warning, verbose } from "../log";
import { NotionPage } from "../NotionPage";

// converts a url to a local link, if it is a link to a page in the Notion site
// only here for plugins, notion won't normally be giving us raw urls (at least not that I've noticed)
// only here for plugins, notion won't normally be giving us raw urls.
// If it finds a URL but can't find the page it points to, it will return undefined.
// If it doesn't find a match at all, it returns undefined.
export function convertInternalUrl(
Expand Down Expand Up @@ -55,6 +55,15 @@ function convertInternalLink(
const labelFromNotion = match[1] || "";
let hrefFromNotion = match[2];


// TODO: This is a hotfix to dodge internal image links parsing
const imageFileExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.svg'];
const isImageLink = imageFileExtensions.some(ext => hrefFromNotion.endsWith(ext));
if (isImageLink) {
verbose(`Link parsing: [InternalLinkPlugin] ${hrefFromNotion} is an internal image link and will be skipped. Make sure it exists !`);
return markdownLink;
}

// Find the last occurrence of either '-' or '/' and take everything to the right to extract id and fragment
const lastSpecialCharIndex = Math.max(hrefFromNotion.lastIndexOf('-'), hrefFromNotion.lastIndexOf('/'));
if (lastSpecialCharIndex !== -1) {
Expand All @@ -70,7 +79,7 @@ function convertInternalLink(
if (!targetPage) {
// About this situation. See https://github.com/sillsdev/docu-notion/issues/9
warning(
`Link parsing: [InternalLinkPlugin] Could not find the target for ${hrefFromNotion}. Note that links to outline sections are not supported > https://github.com/sillsdev/docu-notion/issues/9`
`Link parsing: [InternalLinkPlugin] Could not find a local target for ${hrefFromNotion}. Note that links to other notions pages or outline sections are not supported > https://github.com/sillsdev/docu-notion/issues/9`
);
return "**[Problem Internal Link]**";
}
Expand Down

0 comments on commit bfbc5c5

Please sign in to comment.