Skip to content
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

[Feature]: render unsupported files refs as links to the repo #1792

Open
alyahmedaly opened this issue Jan 28, 2025 · 5 comments
Open

[Feature]: render unsupported files refs as links to the repo #1792

alyahmedaly opened this issue Jan 28, 2025 · 5 comments

Comments

@alyahmedaly
Copy link

What problem does this feature solve?

when referencing files that is not supported like PDF or Power point I think the best is to have a link so you can download it instead of 404 page

What does the proposed API look like?

files which is not supported can be downloadable link

@Timeless0911
Copy link
Contributor

Rspress does not support using pdf/ppt files in _meta.json as well as routes directly.

If you want to render pdf and ppt files or generate a download link for them, you'd better write some components to customize the rendering logic based on mdx or tsx files.

Also, you can use custom-link type in _meta.json to link to a download link service yourself.

@Timeless0911 Timeless0911 marked this as a duplicate of #1791 Jan 28, 2025
@alyahmedaly
Copy link
Author

alyahmedaly commented Jan 29, 2025

The link to the PDF or another document is included in the markdown file rather than _meta.json, and since it’s hosted on the same repository, I
want to be able to reference this file in the documentation using relative links without needing to include the full URL. The approach I’m considering
involves having a configuration like:

{
  "downloadURL": "https://github.com/web-infra-dev/rspress/files"
}

With this setup, the reference URL would be generated as a normal link if the file isn’t supported otherwise.

@Timeless0911
Copy link
Contributor

Timeless0911 commented Jan 29, 2025

write some components to customize the rendering logic based on mdx or tsx files.

What I meant above is you should write a React component which can be named DownloadLink and import it in mdx files.

import React from 'react';

interface DownloadLinkProps {
  pdfUrl: string;
  fileName: string;
}

const DownloadLink: React.FC<DownloadLinkProps> = ({ pdfUrl, fileName }) => {
  // ... download logic
  return (
    <a href="#">
      {fileName}
    </a>
  );
};

export default DownloadLink;
import DownloadLink from './DownloadLink';

<DownloadLink pdfUrl="https://example.com/my-pdf.pdf" fileName="my-pdf.pdf" />

Regarding the hosting and deployment of static resources, PDF or another document can be copied to output folder after Rspress build, thus you can handle these yourself.

@alyahmedaly
Copy link
Author

alyahmedaly commented Jan 29, 2025

That is sold answer, but I don't want to use mdx, I want to use md files instead as we have rspress as step to improve our github docs repo so I want to keep both working at same time until we fully migrate to rspress

@Timeless0911
Copy link
Contributor

Timeless0911 commented Jan 29, 2025

Yeah, what I give is a temporary solution. The future solution strategy is to support preview of pdf files but for other resources type which is not supported by browser natively, it's not our goal to render these resources but we can use download attribute of <a> to make it downloadable.

  1. Support click to preview pdf files directly, eg: [pdf-1](/1.pdf)
  2. Support a download link generation method or built-in component to add a download link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants