Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@saschazar/next-mdx-extended
Advanced tools
Easily wrap MDX pages in React components for Next.js
A Next.js plugin for wrapping Markdown/MDX files in React components, with URL rewriting options. Now supporting serverless Next.js rewrites.
This project was heavily influenced by @next/mdx and of course next-mdx-enhanced.
The underlying standalone Webpack loader may be found here: @saschazar/mdx-extended-loader.
Features | @saschazar/next-mdx-extended | @next/mdx |
---|---|---|
.md files | ✔️ | ✔️ |
.mdx files | ✔️ | ✔️ |
custom layouts | ✔️ | ✖️ |
URL rewriting | ✔️ | ✖️ |
extracting metadata to JSON | ✔️ | ✖️ |
Given the following project tree:
MyApp
|
├─ pages
| ├ index.jsx
| ├ about.mdx
| ├─ blog
| ├ 2020-01-01_first-blog-post.mdx
|
├─ layouts
├ index.jsx
├ custom.jsx
Without any custom options, both .mdx
files would be wrapped in layouts/index.jsx
and the final HTML root would look like this:
├ index.html
├ about.html
├─ blog
├─ 2020
├ first-blog-post.html
yarn add @saschazar/next-mdx-extended
or
npm install --save @saschazar/next-mdx-extended
(Of course, a working Next.js environment is advised to be set up beforehand.)
Create a next.config.js
file in your project root:
// next.config.js
const withMDXExtended = require('@saschazar/next-mdx-extended')();
module.exports = withMDXExtended({
pageExtensions: ['mdx', 'md'],
});
This will assume:
./layouts
, with at least an index.jsx
present, and./pages/blog
.For customization or enhancement of the above parameters, check the options section.
The following options are all optional, and most of them are having default values set:
exportData
boolean
| optional | default:false
Whether to export a posts.json
file containing metadata about the blog posts to ./public
(e.g. for fetching data about blog posts via the async getInitialProps()
hook). Unset by default (and therefore not exported).
⚠️ TL/DR: Whenever activated, it creates a posts.json
file in your ./public
folder, which might cause unwanted side-effects in your git setup!
blogDir
string
| optional | default:blog
The directory to look for blog posts for rewriting the paths for. Only filenames in this directory (incl. sub-directories) are getting parsed, whereas other .md
/.mdx
files are getting transformed into JavaScript as well, but will be served under their initial filename as URL.
format
string
| optional | default:/blog/YYYY/[title]
The definition after how to rewrite the blog post URLs. Possible values are:
YYYY
: The full year, e.g. 2020
(parsed from file name).MM
: The month, e.g. 01
(parsed from file name).DD
: The date, e.g. 02
(parsed from file name).[title]
: Any string wrapped in square brackets will be replaced by its value from the frontmatter metadata. If no such key is found in the metadata, the placeholder gets deleted from the final URL path. [title]
refers to the second half of the filename primarily, after the date was parsed, but might as well be replaced by setting the according value in the frontmatter.Example: /[author]/YYYY/MM/[title]
expects an author
key in the frontmatter metadata. If no title
key is present in the metadata, the parsed title from the filename will be used.
extensions
array
| optional | default:pageExtensions
from the Next.js configuration
The expected file suffixes of the layout files in the layoutsDir
directory.
layoutsDir
string
| optional | default:layouts
The name of the directory (relative to the project root) for where to find the React components, which should later be wrapped around the .md
/.mdx
files.
As this project acts as a superior Next.js plugin wrapper for both @mdx-js/loader and @saschazar/mdx-extended-loader, the options object also takes specific options for those projects.
Please see both repository pages for additional options documentations, (e.g. mdPlugins
, hastPlugins
).
Without MDX, @next/mdx and next-mdx-enhanced, none of this would have happened, or at least in a very different way.
Also, I got inspired a lot by @mxstbr's website respository concerning the exportPathMap
functionality.
Licensed under the MIT license.
Copyright ©️ 2020 Sascha Zarhuber
FAQs
Easily wrap MDX pages in React components
The npm package @saschazar/next-mdx-extended receives a total of 0 weekly downloads. As such, @saschazar/next-mdx-extended popularity was classified as not popular.
We found that @saschazar/next-mdx-extended demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.