@rebilder/render-md 0.4.0 → 0.5.0

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/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ Notable changes to `@rebilder/render-md`. Dates are the day each version reached
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.5.0 (2026-11-30)
8
+
9
+ - Use `renderPricingJsonLd` to add structured pricing data to service and software pages.
10
+
11
+ ## 0.4.1 (2026-10-06)
12
+
13
+ - The source code is public at https://github.com/rebilder/rebilder/tree/main/packages/render-md. `repository` and `bugs` point there, and issues and pull requests are welcome.
14
+
7
15
  ## 0.4.0 (2026-09-28)
8
16
 
9
17
  - `renderFrontmatter(fields)` renders an optional YAML frontmatter block (`title`, `description`, `canonical_url`, `last_updated`) from values you pass. Invalid URLs and dates are dropped. A value is written bare when YAML reads it back as the same string and double-quoted otherwise, so source text cannot end the block. The block is capped at 2 KB. No renderer calls it, so every existing output is byte-for-byte unchanged.
package/README.md CHANGED
@@ -208,4 +208,4 @@ would be exceeded. The returned `profile` identifies what was actually rendered.
208
208
  These are conservative evaluation candidates, with no claim of empirical model
209
209
  improvement. See [SDK updates](https://rebilder.com/docs/sdk-updates).
210
210
 
211
- Full docs: [rebilder.com/docs/sources](https://rebilder.com/docs/sources). Release notes are in `CHANGELOG.md` in this package. Licensed under Apache-2.0.
211
+ Full docs: [rebilder.com/docs/sources](https://rebilder.com/docs/sources). Release notes are in `CHANGELOG.md` in this package. Licensed under Apache-2.0. Source, issues and pull requests: [GitHub](https://github.com/rebilder/rebilder/tree/main/packages/render-md).
package/dist/index.cjs CHANGED
@@ -783,6 +783,165 @@ function renderCollectionJsonLd(collection) {
783
783
  }
784
784
  return out;
785
785
  }
786
+ var PERIOD_UNIT_CODE = {
787
+ hour: "HUR",
788
+ day: "DAY",
789
+ week: "WEE",
790
+ month: "MON",
791
+ quarter: "QAN",
792
+ year: "ANN"
793
+ };
794
+ var PERIOD_UNIT_TEXT = {
795
+ one_time: "one-time",
796
+ hour: "hour",
797
+ day: "day",
798
+ week: "week",
799
+ month: "month",
800
+ quarter: "quarter",
801
+ year: "year"
802
+ };
803
+ function unitPriceSpec(v, label, includeName) {
804
+ const currency = v.value.currency.toUpperCase();
805
+ const minPrice = toDecimalString(v.value);
806
+ const spec = {
807
+ "@type": "UnitPriceSpecification"
808
+ };
809
+ if (includeName && label.trim().length > 0) {
810
+ spec.name = label.trim();
811
+ }
812
+ if (v.maxValue !== void 0) {
813
+ if (v.maxValue.currency.toUpperCase() !== currency) {
814
+ throw new TypeError(
815
+ `Money range currencies must match, got: ${v.value.currency} and ${v.maxValue.currency}`
816
+ );
817
+ }
818
+ if (v.maxValue.amount < v.value.amount) {
819
+ throw new TypeError(
820
+ `Money range maxValue must not be below value, got: ${String(v.value.amount)} and ${String(v.maxValue.amount)}`
821
+ );
822
+ }
823
+ spec.minPrice = minPrice;
824
+ spec.maxPrice = toDecimalString(v.maxValue);
825
+ } else {
826
+ spec.price = minPrice;
827
+ }
828
+ spec.priceCurrency = currency;
829
+ const perText = v.per?.trim();
830
+ if (v.period !== void 0) {
831
+ const unitCode = PERIOD_UNIT_CODE[v.period];
832
+ if (unitCode !== void 0) spec.unitCode = unitCode;
833
+ spec.unitText = PERIOD_UNIT_TEXT[v.period];
834
+ } else if (perText !== void 0 && perText.length > 0) {
835
+ spec.unitText = perText;
836
+ }
837
+ if (perText !== void 0 && perText.length > 0) {
838
+ spec.referenceQuantity = {
839
+ "@type": "QuantitativeValue",
840
+ value: 1,
841
+ unitText: perText
842
+ };
843
+ }
844
+ return spec;
845
+ }
846
+ function propertyValueFor(fact) {
847
+ const name = fact.label.trim();
848
+ if (name.length === 0) return null;
849
+ switch (fact.value.type) {
850
+ case "number": {
851
+ if (!Number.isFinite(fact.value.value)) return null;
852
+ const text2 = String(fact.value.value);
853
+ if (text2.includes("e") || text2.includes("E")) return null;
854
+ const prop = {
855
+ "@type": "PropertyValue",
856
+ name,
857
+ value: fact.value.value
858
+ };
859
+ const unit = fact.value.unit?.trim();
860
+ if (unit !== void 0 && unit.length > 0) prop.unitText = unit;
861
+ return prop;
862
+ }
863
+ case "boolean":
864
+ return { "@type": "PropertyValue", name, value: fact.value.value };
865
+ case "text": {
866
+ const value = fact.value.value.trim();
867
+ return value.length > 0 ? { "@type": "PropertyValue", name, value } : null;
868
+ }
869
+ case "list":
870
+ return fact.value.value.length > 0 ? { "@type": "PropertyValue", name, value: fact.value.value.join(", ") } : null;
871
+ case "date":
872
+ return isIsoDate(fact.value.value) ? { "@type": "PropertyValue", name, value: fact.value.value } : null;
873
+ case "url":
874
+ return isAllowedUrl(fact.value.value) ? { "@type": "PropertyValue", name, value: fact.value.value } : null;
875
+ case "money":
876
+ case "hours":
877
+ return null;
878
+ }
879
+ }
880
+ function pricingOffer(item) {
881
+ const out = {
882
+ "@type": "Offer",
883
+ name: item.title
884
+ };
885
+ if (isAllowedUrl(item.url)) out.url = item.url;
886
+ if (item.summary !== void 0 && item.summary.trim().length > 0) {
887
+ out.description = item.summary;
888
+ }
889
+ const facts = item.facts ?? [];
890
+ const moneyFacts = [];
891
+ const additionalProperties = [];
892
+ for (const fact of facts) {
893
+ if (fact.value.type === "money") {
894
+ moneyFacts.push({ label: fact.label, value: fact.value });
895
+ } else {
896
+ const prop = propertyValueFor(fact);
897
+ if (prop !== null) additionalProperties.push(prop);
898
+ }
899
+ }
900
+ if (moneyFacts.length > 0) {
901
+ const specs = moneyFacts.map(
902
+ (mf) => unitPriceSpec(mf.value, mf.label, moneyFacts.length > 1)
903
+ );
904
+ const primary = moneyFacts[0];
905
+ if (primary.value.maxValue === void 0) {
906
+ out.price = toDecimalString(primary.value.value);
907
+ }
908
+ out.priceCurrency = primary.value.value.currency.toUpperCase();
909
+ out.priceSpecification = specs.length === 1 ? specs[0] : specs;
910
+ }
911
+ if (additionalProperties.length > 0) {
912
+ out.itemOffered = {
913
+ "@type": "Service",
914
+ name: item.title,
915
+ additionalProperty: additionalProperties
916
+ };
917
+ }
918
+ return out;
919
+ }
920
+ function renderPricingJsonLd(collection, options = {}) {
921
+ const entityType = options.entityType ?? "SoftwareApplication";
922
+ const out = {
923
+ "@context": "https://schema.org",
924
+ "@type": entityType
925
+ };
926
+ if (isAllowedUrl(collection.url)) out.url = collection.url;
927
+ if (collection.title !== void 0) out.name = collection.title;
928
+ if (collection.language !== void 0 && isLanguageTag(collection.language)) {
929
+ out.inLanguage = collection.language;
930
+ }
931
+ if (entityType === "SoftwareApplication") {
932
+ if (options.applicationCategory !== void 0 && options.applicationCategory.trim().length > 0) {
933
+ out.applicationCategory = options.applicationCategory.trim();
934
+ }
935
+ if (options.operatingSystem !== void 0 && options.operatingSystem.trim().length > 0) {
936
+ out.operatingSystem = options.operatingSystem.trim();
937
+ }
938
+ }
939
+ out.offers = collection.items.slice(0, MAX_COLLECTION_ROWS).map(pricingOffer);
940
+ if (collection.updated !== void 0 && isIsoDate(collection.updated)) {
941
+ out.dateModified = collection.updated;
942
+ }
943
+ return out;
944
+ }
786
945
 
787
946
  // src/compatibility.ts
788
947
  var BASELINE_PROFILE = Object.freeze({
@@ -920,6 +1079,7 @@ exports.renderCollectionMarkdown = renderCollectionMarkdown;
920
1079
  exports.renderDocumentMarkdown = renderDocumentMarkdown;
921
1080
  exports.renderFrontmatter = renderFrontmatter;
922
1081
  exports.renderPolicyMarkdown = renderPolicyMarkdown;
1082
+ exports.renderPricingJsonLd = renderPricingJsonLd;
923
1083
  exports.renderProductJsonLd = renderProductJsonLd;
924
1084
  exports.renderProductMarkdown = renderProductMarkdown;
925
1085
  exports.validateCompatibilityProfile = validateCompatibilityProfile;