Skip to content

fix: #337 add file name transfrom #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

StringKe
Copy link

fix: #337

Use transliteration for filenames in other languages.

@changeset-bot
Copy link

changeset-bot bot commented Nov 25, 2022

⚠️ No Changeset found

Latest commit: 49825f5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

💥 An error occurred when fetching the changed packages and changesets in this PR
Some errors occurred when validating the changesets config:
The package or glob expression "examples-*" is specified in the `ignore` option but it is not found in the project. You may have misspelled the package name or provided an invalid glob expression. Note that glob expressions must be defined according to https://www.npmjs.com/package/micromatch.

@stale
Copy link

stale bot commented Dec 15, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale label Dec 15, 2022
@schickling
Copy link
Collaborator

Sorry for the delay. I hope to get a chance to look into this soon! 🙏

@stale stale bot removed the meta: stale label Dec 15, 2022
@stale
Copy link

stale bot commented Jan 4, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale label Jan 4, 2023
@StringKe
Copy link
Author

StringKe commented Jan 5, 2023

up

@stale stale bot removed the meta: stale label Jan 5, 2023
@schickling
Copy link
Collaborator

Thanks a lot for this PR @StringKe. I agree that we should try to address the underlaying issue (as described in #337), however, the transliteration package seems to add 1.6MB of dependencies which I'm wary to add.

Maybe you (or someone else) is aware of a way to accomplish the same but using more standardised platform APIs?

@schickling schickling added the help wanted Extra attention is needed label Jan 16, 2023
@StringKe
Copy link
Author

StringKe commented Jan 16, 2023

hi, @schickling
There is no good way to do this; there are too many languages in the world to use anything but a dictionary-like function to mirror the conversion.

I also have another method

Use unicode as filename, this does not add extra volume but is already unreadable for filenames and the generated url is not friendly enough to read and remember.

origin: 你好.mdx
eng_origin: hello.mdx
transliteration: ni-hao.mdx
unicode: 20320-22909.mdx

origin: 这是一个案例文档
eng_origin: this-is-a-case-document.mdx
transliteration: zhe-shi-yi-ge-an-li-wen-dang.mdx
unicode: 36825-26159-19968-20010-26696-20363-25991-26723.mdx

@schickling
Copy link
Collaborator

I see. Let me see whether I can think of some kind of "user-configuration" way to enable the use case above.

@schickling schickling added this to the Next milestone Jan 16, 2023
@StringKe
Copy link
Author

I see. Let me see whether I can think of some kind of "user-configuration" way to enable the use case above.

I favor using this approach by providing a slugify method to allow processing of filenames.

@StringKe
Copy link
Author

Close, there has been another result.

@StringKe StringKe closed this Jan 16, 2023
@tansongchen
Copy link

@StringKe What do you mean by "there has been another result"? Is there any workaround to this problem?
@schickling Any updates on that?

@tansongchen
Copy link

I am currently a Flowershow user and I cannot use Chinese in file names because it depends on Contentlayer

@StringKe
Copy link
Author

StringKe commented Apr 5, 2023

@StringKe What do you mean by "there has been another result"? Is there any workaround to this problem? @schickling Any updates on that?

You can modify the specified files with pnpm patch or npm patch pacakge to solve the problem for a short time.

In the long run, you still need this repository to support custom filename conversions

@huanfe1
Copy link

huanfe1 commented May 29, 2023

I also meet the same problem and tried some solutions.

Here is my solution.

I add a hash-sum package.

import hash from 'hash-sum'

And change this line of code

const makeVariableName = flow(idToFileName, (_) => camelCase(_, { stripRegexp: /[^A-Z0-9-\_]/gi }))

To

  const makeVariableName = flow(hash, idToFileName, (_) => camelCase(_, { stripRegexp: /[^A-Z0-9\_]/gi }))

image

Or don't add any package.

Change code to

const makeVariableName = flow((_) => Buffer.from(_).toString('base64'), idToFileName, (_) => camelCase(_, { stripRegexp: /[^A-Z0-9\_]/gi }));

But this may lead to variable names that are too long.

image

Or like #431 change regular expression, add Chinese to it, use Chinese variable names.

const makeVariableName = flow(idToFileName, (_) => camelCase(_, { stripRegexp: /[^\u4e00-\u9fa5A-Z0-9\_]/gi }));

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request support for naming files in other languages
4 participants