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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for reference style links #305

Closed
jcalcaben opened this issue Apr 16, 2021 · 3 comments 路 Fixed by #340
Closed

Add support for reference style links #305

jcalcaben opened this issue Apr 16, 2021 · 3 comments 路 Fixed by #340
Labels
enhancement New feature or request

Comments

@jcalcaben
Copy link
Contributor

馃檵 Feature Request

Add support for reference-style links in MDX for static builds.

馃 Expected Behavior

The following markdown:

This is an [internal reference-style link][].

[internal reference-style link]: /path/to/page/

Should be rendered as a link with the pathPrefix prepended to the destination when creating the static builds for staging and production.

馃槸 Current Behavior

Staging and production builds do not prepend the link destination with the site's pathPrefix.

This can be seen when building content that uses reference-style links and publish to staging.
The link paths from this content will not have the prefix prepended to the href.

馃拋 Possible Solution

Add the remark-inline-links plugin to the MDX plugin's options.remarkPlugins array.

   {
        resolve: `gatsby-plugin-mdx`,
        options: {
          extensions: [`.mdx`, `.md`],
          defaultLayouts: {
            default: require.resolve(`./src/components/MDXFilter/index.js`)
          },
          rehypePlugins: [require(`rehype-slug`)],
          plugins: [`gatsby-remark-copy-linked-files`, `gatsby-remark-images-remote`],
          gatsbyRemarkPlugins: [
            {
              resolve: `gatsby-remark-copy-linked-files`,
              options: {
                ignoreFileExtensions: [`png`, `jpg`, `jpeg`, `bmp`, `tiff`, `md`, `mdx`]
              }
            },
            {
              resolve: `gatsby-remark-images-remote`,
              options: {
                maxWidth: LARGE_SCREEN_WIDTH,
                linkImagesToOriginal: false,
                withWebp: { quality: 80 },
                disableBgImage: true,
                backgroundColor: 'none'
              }
            }
          ],
+        remarkPlugins: [require('remark-inline-links')],
        }
      },

This transforms reference-style links in the underlying markdown into inline links, which produce the correct links in static builds.

馃敠 Context

The markdown content I am migrating into this framework almost exclusively uses reference-style links, which is valid markdown syntax.
Using this format makes authoring, reading, and reviewing the raw markdown easier.

For local development builds, this is not a problem because pathPrefix is not used, but when uploading static builds to the staging server where the content does not sit at the root, this becomes an issue.

馃捇 Examples

For Magento Cloud specific deployment instructions, see the [Magento Cloud deployment][] tutorial.

[magento cloud deployment]: /tutorials/production-deployment/magento-cloud/

馃Б Your Company/Team

Magento/devdocs

馃巵 Tracking Ticket (optional)

@jcalcaben jcalcaben added the enhancement New feature or request label Apr 16, 2021
@icaraps
Copy link
Contributor

icaraps commented Apr 22, 2021

@jcalcaben did you try the remark-inline-links you mentioned ? Does it work ?
You can try it by checking out https://github.com/adobe/gatsby-theme-aio then cd packages/gatsby-theme-aio && yarn add remark-inline-links then add the config as you said in https://github.com/adobe/gatsby-theme-aio/blob/main/packages/gatsby-theme-aio/gatsby-config.js then at the project root yarn dev && open localhost:8000 and update an index.md file with reference-style links to check if it's working.

@jcalcaben
Copy link
Contributor Author

@icaraps yes, this does solve the issue. I can create a PR for this change, but it may not be necessary.

I tracked down the source of the bug to Gatsby itself, reported it, and created a PR to fix it on their end.

Since my PR just got merged, we just have to wait for the next release of the gatsby-plugin-mdx package.

@icaraps
Copy link
Contributor

icaraps commented Apr 22, 2021

Awesome thanks ! 馃憦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants