You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOTE: In the above, we are using `npx` to use the latest `notion-pull-mdx`. A more conservative approach would be to `npm i cross-var notion-pull-mdx` and then create a script in your package.json like this:
Most projects should probably commit the current markdown and image files each time you run notion-pull-mdx.
@@ -77,11 +87,19 @@ Links from one document to another in Notion are not yet converted to local link
77
87
78
88
notion-pull-mdx makes some attempt to keep the right order of things, but there are definitely cases where it isn't smart enough yet.
79
89
80
-
# Localization
90
+
# Text Localization
81
91
82
92
Localize your files in Crowdin (or whatever) based on the markdown files, not in Notion. For how to do this with Docusaurus, see [Docusaurus i18n](https://docusaurus.io/docs/i18n/crowdin).
83
93
84
-
You may also need to localize screenshots. Crowdin can also handle localizing assets, but this library currently supports a different approach. If you place for example `fr https:\\imgur.com\1234.png` in the caption of a screenshot in Notion, `notion-pull-mdx` will fetch that image and save it locally with the same name as the primary screenshot, but with "-fr" appended. So you'd get for example `static\img\9876.png` and `static\img\9876-fr.png`. To get the French version to show, you'd need to add that "-fr" to the markdown link when you localize the page's text in crowdin. If there is a way, maybe this modification of the markdown can be made automatic in the future so that you automatically get the right image version.
94
+
# Screenshot Localization
95
+
96
+
The only way we know of to provide localization of image in the current Docusaurus (2.0) is to place the images in the same directory as the markdown, and use relative paths for images. Most projects probably won't localize _every_ image, so we also need a way to "fall back" to the original screenshot when the localized one is missing. `notion-pull-mdx` facilitates this. If no localized version of an image is available, `notion-pull-mdx` places a copy of the original image into the correct location.
97
+
98
+
So how do you provide these localized screenshot files? Crowdin can handle localizing assets, and in the future we may support that. For now, we currently support a different approach. If you place for example `fr https:\\imgur.com\1234.png` in the caption of a screenshot in Notion, `notion-pull-mdx` will fetch that image and save it in the right place to be found when in French mode. Getting URLs to screenshots is easy with screenshot utilities such as [Greenshot](https://getgreenshot.org/) that support uploading to imgur. Note that `notion-pull-mdx` stores a copy of all images in your source tree, so you wouldn't lose the images if imgur were to go away.
99
+
100
+
NOTE: that as far as I can tell, when you run `docusaurus start` docusaurus 2.0 offers the language picker but it doesn't actually work. So to test out the localized version, do `docusaurus build` followed by `docusaurus serve`.
101
+
102
+
NOTE: if you just localize an image, it will not get picked up. You also must localize the page that uses the image. Otherwise, Docusaurus will use the English document and when that asks for `./the-image-path`, it will find the image there in the English section, not your other language section.
"imageOutputPath was declared, but one or more localizedUrls were found too. If you are going to localize screenshots, then you can't declare an imageOutputPath."
36
+
);
37
+
}
38
+
39
+
imageSet.filePathToUseInMarkdown=
40
+
(imagePrefix?.length>0 ? imagePrefix : ".")+
41
+
"/"+
42
+
imageSet.outputFileName;
43
+
}else{
44
+
error(
45
+
`Something wrong with the filetype extension on the blob we got from ${imageSet.primaryUrl}`
letimageOutputPath="";// default to putting in the same directory as the document referring to it.
10
+
letimagePrefix="";// default to "./"
11
+
12
+
// we parse a notion image and its caption into what we need, which includes any urls to localized versions of the image that may be embedded in the caption
fs.createWriteStream(path).write(buffer);// async but we're not waiting
89
+
}else{
90
+
verbose(`image already filled: ${path}`);
83
91
}
84
-
returnoutputFileName;
85
92
}
86
93
87
-
functionhashOfString(s: string){
88
-
lethash=0;
89
-
for(leti=0;i<s.length;++i)
90
-
hash=Math.imul(31,hash)+s.charCodeAt(i);
91
-
92
-
returnMath.abs(hash);
93
-
}
94
-
95
-
// we parse a notion image and its caption into what we need, which includes any urls to localized versions of the image that may be embedded in the caption
0 commit comments