-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #979 from Bedrock-OSS/licensing
Integrate licensing
- Loading branch information
Showing
9 changed files
with
361 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script setup lang="ts"> | ||
import { computed } from "vue"; | ||
import useData from "../../composables/data"; | ||
import NavLink from "../navigation/NavLink.vue"; | ||
import { data as licenses } from "../../data/licenses/licenses.data"; | ||
const { frontmatter } = useData(); | ||
const normalizedLicenses = computed(() => { | ||
const { license } = frontmatter.value; | ||
if (typeof license === "string") return { main: license }; | ||
return license; | ||
}); | ||
const mainLicense = computed(() => licenses[normalizedLicenses.value.main]); | ||
const codeLicense = computed(() => licenses[normalizedLicenses.value.code]); | ||
</script> | ||
|
||
<template> | ||
<hr style="margin-block: 1em" /> | ||
<p> | ||
Text and image content on this page is licensed under the | ||
<NavLink :link="mainLicense.link">{{ mainLicense.title }}</NavLink> | ||
</p> | ||
<p v-if="codeLicense"> | ||
Code samples on this page are licensed under the | ||
<NavLink :link="codeLicense.link">{{ codeLicense.title }}</NavLink> | ||
</p> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { readdirSync, statSync, readFileSync } from "fs"; | ||
import { defineLoader } from "vitepress"; | ||
import matter from "gray-matter"; | ||
import { join } from "path"; | ||
|
||
import { License } from "../../types"; | ||
import config from "../config"; | ||
|
||
import validateLicense from "./validateLicense"; | ||
|
||
export interface Licenses { | ||
[id: string]: License; | ||
} | ||
|
||
declare const data: Licenses; | ||
export { data }; | ||
|
||
const licensesDirectory = join(config.srcDir, "licenses"); | ||
|
||
export default defineLoader({ | ||
watch: join(licensesDirectory, "*.md"), | ||
load() { | ||
const licenses: Licenses = {}; | ||
|
||
const entries = readdirSync(licensesDirectory); | ||
|
||
for (const entry of entries) { | ||
const joinedPath = join(licensesDirectory, entry); | ||
const stats = statSync(joinedPath); | ||
|
||
// Don't include non-markdown files, or the section index page | ||
if (!stats.isFile() || !entry.endsWith(".md") || entry === "index.md") continue; | ||
|
||
const licenseId = entry.replace(/\.md$/, ""); | ||
|
||
const licenseMarkdown = readFileSync(joinedPath, "utf-8"); | ||
const frontMatter = matter(licenseMarkdown); | ||
|
||
validateLicense(licenseId, frontMatter); | ||
|
||
const { data } = frontMatter; | ||
|
||
licenses[licenseId] = { | ||
link: "/licenses/" + licenseId, | ||
title: data.title, | ||
}; | ||
} | ||
|
||
return licenses; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { GrayMatterFile } from "gray-matter"; | ||
|
||
export default function validateLicense(id: string, { data }: GrayMatterFile<string>) { | ||
const errors: string[] = []; | ||
|
||
if (data.title === undefined) { | ||
errors.push("A license title must be defined but none was found."); | ||
} | ||
if (data.source === undefined) { | ||
errors.push("A license source link must be defined but none was found."); | ||
} | ||
|
||
if (errors.length > 0) { | ||
throw new Error(`License "${id}" has invalid frontmatter:\n- ${errors.join("\n- ")}\n`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.