@t8/docsgen 0.1.58 → 0.1.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,5 @@
1
- # @t8/docsgen
2
-
3
- *Generates docs from READMEs*
4
-
5
1
  ```sh
6
- # with specified docs entries (e.g. in docsgen.config.json)
2
+ # with specified entries (e.g. in docsgen.config.json)
7
3
  npx @t8/docsgen [...<entry id or dir>]
8
4
 
9
5
  # without entries
package/dist/bin.js CHANGED
@@ -531,6 +531,7 @@ async function getParsedContent(ctx) {
531
531
  let badges = [];
532
532
  let title = "";
533
533
  let description = [];
534
+ let intro = [];
534
535
  let features = [];
535
536
  let note = [];
536
537
  let installation = "";
@@ -561,7 +562,8 @@ async function getParsedContent(ctx) {
561
562
  } else {
562
563
  let installationCode = getInstallationCode(element);
563
564
  if (installationCode) installation = installationCode;
564
- else description.push(outerHTML);
565
+ else if (description.length === 0) description.push(outerHTML);
566
+ else intro.push(outerHTML);
565
567
  }
566
568
  } else {
567
569
  let installationCode = getInstallationCode(element);
@@ -576,10 +578,15 @@ async function getParsedContent(ctx) {
576
578
  ...navLinkMap,
577
579
  ...linkMap
578
580
  });
581
+ if (intro.length !== 0 && description.length !== 0 && !description[0].startsWith("<p><em>")) {
582
+ intro.unshift(description[0]);
583
+ description = [];
584
+ }
579
585
  return {
580
586
  badges: postprocessBadges(joinLines(badges)),
581
587
  title,
582
588
  description: joinLines(description),
589
+ intro: joinLines(intro),
583
590
  features: joinLines(features),
584
591
  note: joinLines(note),
585
592
  installation,
@@ -632,6 +639,7 @@ async function setContent(ctx) {
632
639
  let counterContent = getCounterContent(ctx);
633
640
  let escapedName = escapeHTML(name);
634
641
  let escapedTitle = title ? escapeHTML(title) : escapedName;
642
+ let escapedPackageDescription = escapeHTML(packageDescription);
635
643
  let packageVersion = (await exec(`npm view ${packageName} version`)).stdout.trim().split(".").slice(0, 2).join(".");
636
644
  let packageUrl = `https://unpkg.com/${packageName}@${packageVersion}`;
637
645
  let rootAttrs = "";
@@ -669,7 +677,7 @@ ${getInjectedContent(ctx, "redirect", "body")}
669
677
  );
670
678
  return;
671
679
  }
672
- let { badges, description, features, installation, sections, nav } = await getParsedContent(ctx);
680
+ let { badges, description, intro, features, installation, sections, nav } = await getParsedContent(ctx);
673
681
  let navContent = await getNav(ctx, nav);
674
682
  let dirs = [contentDir];
675
683
  await Promise.all(
@@ -743,8 +751,8 @@ ${getInjectedContent(ctx, "section", "body")}
743
751
  <head>
744
752
  <meta charset="utf-8">
745
753
  <meta name="viewport" content="width=device-width, initial-scale=1">
746
- <meta name="description" content="${escapedTitle}${packageDescription ? `: ${escapeHTML(packageDescription)}` : ""}">
747
- <title>${escapedTitle}${packageDescription ? ` | ${escapeHTML(packageDescription)}` : ""}</title>
754
+ <meta name="description" content="${escapedTitle}${escapedPackageDescription ? `: ${escapedPackageDescription}` : ""}">
755
+ <title>${escapedTitle}${escapedPackageDescription ? ` | ${escapedPackageDescription}` : ""}</title>
748
756
  <link rel="stylesheet" href="${packageUrl}/dist/css/base.css">
749
757
  <link rel="stylesheet" href="${packageUrl}/dist/css/index.css">
750
758
  ${iconTag}
@@ -761,7 +769,7 @@ ${getInjectedContent(ctx, "section", "body")}
761
769
  </div>
762
770
  <h1>${getTitle(ctx, { cover: true })}</h1>
763
771
  <div class="description">
764
- ${description}
772
+ ${description || (escapedPackageDescription ? `<p><em>${escapedPackageDescription}</em><p>` : "")}
765
773
  </div>
766
774
  <p class="actions">
767
775
  <a href="${root}start" class="primary button">Docs</a>
@@ -772,12 +780,19 @@ ${getInjectedContent(ctx, "section", "body")}
772
780
  <p class="installation"><code>${installation}</code></p>
773
781
  <script>document.querySelectorAll(".badges img").forEach(img=>{let c=img.closest(".badge");if(c){if(img.complete)c.classList.add("loaded");else{img.onload=()=>{c.classList.add("loaded");};img.onerror=()=>{c.classList.add("failed");};}}});</script>
774
782
  </section>
775
- ${features ? `
783
+ ${intro || features ? `
776
784
  <section class="intro">
785
+ ${intro ? `
786
+ <div class="intro-content">
787
+ ${intro}
788
+ </div>
789
+ ` : ""}
790
+ ${features ? `
777
791
  <div class="features">
778
792
  <h2>Features</h2>
779
793
  ${features}
780
794
  </div>
795
+ ` : ""}
781
796
  </section>
782
797
  ` : ""}
783
798
  </main>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/docsgen",
3
- "version": "0.1.58",
3
+ "version": "0.1.60",
4
4
  "description": "",
5
5
  "main": "dist/bin.js",
6
6
  "bin": {
@@ -132,6 +132,7 @@ export async function getParsedContent(ctx: Context) {
132
132
  let badges: string[] = [];
133
133
  let title = "";
134
134
  let description: string[] = [];
135
+ let intro: string[] = [];
135
136
  let features: string[] = [];
136
137
  let note: string[] = [];
137
138
  let installation = "";
@@ -170,7 +171,8 @@ export async function getParsedContent(ctx: Context) {
170
171
  let installationCode = getInstallationCode(element);
171
172
 
172
173
  if (installationCode) installation = installationCode;
173
- else description.push(outerHTML);
174
+ else if (description.length === 0) description.push(outerHTML);
175
+ else intro.push(outerHTML);
174
176
  }
175
177
  } else {
176
178
  let installationCode = getInstallationCode(element);
@@ -190,10 +192,20 @@ export async function getParsedContent(ctx: Context) {
190
192
  ...linkMap,
191
193
  });
192
194
 
195
+ if (
196
+ intro.length !== 0 &&
197
+ description.length !== 0 &&
198
+ !description[0].startsWith("<p><em>")
199
+ ) {
200
+ intro.unshift(description[0]);
201
+ description = [];
202
+ }
203
+
193
204
  return {
194
205
  badges: postprocessBadges(joinLines(badges)),
195
206
  title,
196
207
  description: joinLines(description),
208
+ intro: joinLines(intro),
197
209
  features: joinLines(features),
198
210
  note: joinLines(note),
199
211
  installation,
@@ -35,6 +35,7 @@ export async function setContent(ctx: Context) {
35
35
  let counterContent = getCounterContent(ctx);
36
36
  let escapedName = escapeHTML(name);
37
37
  let escapedTitle = title ? escapeHTML(title) : escapedName;
38
+ let escapedPackageDescription = escapeHTML(packageDescription);
38
39
 
39
40
  let packageVersion = (await exec(`npm view ${packageName} version`)).stdout
40
41
  .trim()
@@ -88,7 +89,7 @@ ${getInjectedContent(ctx, "redirect", "body")}
88
89
  return;
89
90
  }
90
91
 
91
- let { badges, description, features, installation, sections, nav } =
92
+ let { badges, description, intro, features, installation, sections, nav } =
92
93
  await getParsedContent(ctx);
93
94
 
94
95
  let navContent = await getNav(ctx, nav);
@@ -171,8 +172,8 @@ ${getInjectedContent(ctx, "section", "body")}
171
172
  <head>
172
173
  <meta charset="utf-8">
173
174
  <meta name="viewport" content="width=device-width, initial-scale=1">
174
- <meta name="description" content="${escapedTitle}${packageDescription ? `: ${escapeHTML(packageDescription)}` : ""}">
175
- <title>${escapedTitle}${packageDescription ? ` | ${escapeHTML(packageDescription)}` : ""}</title>
175
+ <meta name="description" content="${escapedTitle}${escapedPackageDescription ? `: ${escapedPackageDescription}` : ""}">
176
+ <title>${escapedTitle}${escapedPackageDescription ? ` | ${escapedPackageDescription}` : ""}</title>
176
177
  <link rel="stylesheet" href="${packageUrl}/dist/css/base.css">
177
178
  <link rel="stylesheet" href="${packageUrl}/dist/css/index.css">
178
179
  ${iconTag}
@@ -189,7 +190,7 @@ ${getInjectedContent(ctx, "section", "body")}
189
190
  </div>
190
191
  <h1>${getTitle(ctx, { cover: true })}</h1>
191
192
  <div class="description">
192
- ${description}
193
+ ${description || (escapedPackageDescription ? `<p><em>${escapedPackageDescription}</em><p>` : "")}
193
194
  </div>
194
195
  <p class="actions">
195
196
  <a href="${root}start" class="primary button">Docs</a>
@@ -201,13 +202,28 @@ ${getInjectedContent(ctx, "section", "body")}
201
202
  <script>document.querySelectorAll(".badges img").forEach(img=>{let c=img.closest(".badge");if(c){if(img.complete)c.classList.add("loaded");else{img.onload=()=>{c.classList.add("loaded");};img.onerror=()=>{c.classList.add("failed");};}}});</script>
202
203
  </section>
203
204
  ${
204
- features
205
+ intro || features
205
206
  ? `
206
207
  <section class="intro">
208
+ ${
209
+ intro
210
+ ? `
211
+ <div class="intro-content">
212
+ ${intro}
213
+ </div>
214
+ `
215
+ : ""
216
+ }
217
+ ${
218
+ features
219
+ ? `
207
220
  <div class="features">
208
221
  <h2>Features</h2>
209
222
  ${features}
210
223
  </div>
224
+ `
225
+ : ""
226
+ }
211
227
  </section>
212
228
  `
213
229
  : ""