Provide a way to populate field values from Markdown/MDX processing pipeline
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, markdown
- Lĩnh vực
- tooling
Hướng nghiên cứu
Issue không nêu các tệp triển khai hoặc các bài kiểm thử; hãy bắt đầu bằng cách lần theo pipeline xử lý Markdown/MDX và cách vFile.data do plugin tạo ra hiện đang được xử lý. Công việc được xem là hoàn tất khi các giá trị đó được cung cấp trong đối tượng nội dung được tạo cùng với frontmatter, code và _raw, kèm theo độ bao phủ cho ví dụ searchMeta.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Feature:
I'd like to use an MDX plugin to create programmatic meta (variable declarations) that can then be exposed in the final object contentlayer provides.
Use case:
An example of here this would be useful is generating a TOC, creating a list of unique keywords, etc.
Work around:
Use computed fields (which don't expose the the raw AST)
Related issues: https://github.com/kentcdodds/mdx-bundler/issues/169
Consider the following config structure
export default makeSource({
contentDirPath: "content",
documentTypes: [Posts, Things, People],
mdx: {
rehypePlugins: [rehypeSlug, rehypeAutolinkHeadings, searchMeta],
},
});
Where searchMeta looks at paragraph nodes of mhast, grabs a list of unique words, and adds them to the metadata as searchMeta.
A markdown file with the structure of:
---
title: Hello World
slug: hello-world
---
Hello World! Please say Hello!
Would generate a final object of:
{
"title": "Hello World",
"slug": "hello-world",
"searchMeta": ["hello", "world", "please", "say"],
"code": "().....",
"_raw": "..."
}
For sake of complete, if not ugly code, here's a working example of the plugin that adds searchMeta to the data attribute of the vFile in the rehype plugin chain.
import { visit } from "unist-util-visit";
export default function searchMeta() {
return (tree, file) => {
visit(tree, { tagName: "p" }, (node) => {
let words = node.children.reduce((collector, current) => {
if (typeof current.value === "string") {
let wordList = current.value
.split(" ")
.filter((word) => !word.includes(":"))
.map((word) => word.toLowerCase().replace(/[^a-z0-9]/gi, ""))
.filter((word) => word.length > 3);
let newCollector = new Set([...wordList, ...collector]);
return newCollector;
} else {
return collector;
}
}, new Set());
file.data.searchMeta = [...words];
});
};
}
- Ngôn ngữ chính
- TypeScript
- Star
- 3.5k
- Fork
- 192
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của contentlayerdev/contentlayer
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
contentlayerdev/contentlayer#506 · 84 bình luận · 47 reaction ·
-
Poor/broken monorepo DX: can't specify .contentlayer/ output path, no docs for custom config path Đang mởhelp wanted meta: never-stale needs-research
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
contentlayerdev/contentlayer#464 · 4 bình luận · 9 reaction ·
-
State of the project Đang mởmeta: never-stale
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
contentlayerdev/contentlayer#429 · 49 bình luận · 83 reaction ·
-
meta: never-stale topic: markdown/mdx
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
contentlayerdev/contentlayer#421 · 4 reaction ·
-
meta: never-stale needs-research topic: schema
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
contentlayerdev/contentlayer#420 ·
Tất cả issue của contentlayerdev/contentlayer
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
ontola/atomic-server#1625 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
melgarafael/DeskcommCRM#1451 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
-
bug via-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bot:ai-assisted component:compact-js status:untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
midnightntwrk/midnight-sdk#403 ·