MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / addJekyllMetadata

Function addJekyllMetadata

packages/tsdocs/src/update-api-md-docs.ts:61–147  ·  view source on GitHub ↗

* Prepend Jekyll metadata to markdown files * * @param lernaRootDir - Root directory for the monorepo * @param options - Options for api docs

(
  lernaRootDir: string,
  options: ApiDocsOptions,
)

Source from the content-addressed store, hash-verified

59 * @param options - Options for api docs
60 */
61async function addJekyllMetadata(
62 lernaRootDir: string,
63 options: ApiDocsOptions,
64) {
65 const apiDocsRoot = path.join(lernaRootDir, options.apiDocsGenerationPath!);
66 const exists = await fs.pathExists(apiDocsRoot);
67 if (!exists) {
68 console.error('No API docs found at %s.', apiDocsRoot);
69 return false;
70 }
71 const apiFiles = await fs.readdir(apiDocsRoot);
72 for (const f of apiFiles) {
73 /* istanbul ignore if */
74 if (!f.endsWith('.md')) continue;
75 const name = f.replace(/\.md$/, '');
76 const isPackage = f.match(/^[^\.]+.md$/) && f !== 'index.md';
77
78 /* istanbul ignore if */
79 if (!options.silent) {
80 // Only print the package level name
81 if (isPackage) {
82 console.log('Updating *.md files for %s', name);
83 }
84 }
85
86 const docFile = path.join(apiDocsRoot, f);
87 let doc = await fs.readFile(docFile, 'utf-8');
88 doc = doc.replace(/<td>/g, '<td markdown="1">');
89
90 const pkgName = name.split('.')[0];
91 // Calculate the relative uri for the package
92 let relativeUri = `packages/${pkgName}`;
93 const pkg = options.lernaPackages?.[pkgName];
94 if (pkg != null) {
95 relativeUri = path
96 .relative(pkg.rootPath, pkg.location)
97 .split(path.sep) // On Windows, the relative path has `\`
98 .join('/');
99 }
100 const pkgUrl =
101 f === 'index.md'
102 ? 'https://github.com/loopbackio/loopback-next'
103 : `https://github.com/loopbackio/loopback-next/tree/master/${relativeUri}`;
104
105 if (isPackage && options.generateDefaultPackageDoc) {
106 const modelFile = path.join(
107 path.join(
108 lernaRootDir,
109 options.apiDocsExtractionPath!,
110 `models/${name}.api.json`,
111 ),
112 );
113 /**
114 * "kind": "Package",
115 * "canonicalReference": "@loopback/authentication",
116 * "docComment": "",
117 * "name": "@loopback/authentication",
118 */

Callers 1

updateApiDocsFunction · 0.85

Calls 3

errorMethod · 0.80
matchMethod · 0.65
logMethod · 0.65

Tested by

no test coverage detected