Skip to content

Commit

Permalink
Support only GitHub (#35)
Browse files Browse the repository at this point in the history
* Add `localePathConstructor` & improve git hosting links

* Support only GitHub

* Create rare-buckets-roll.md
  • Loading branch information
yanthomasdev authored Nov 4, 2023
1 parent df0ab02 commit 99e4ee6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-buckets-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lunariajs/core": patch
---

Move into supporting only GitHub
24 changes: 11 additions & 13 deletions packages/core/src/dashboard/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ export const LocaleDetails = (
${missingPages.map(
(page) => html`
<li>
${GitHostingLink(page.gitHostingUrl, page.sharedPath)}
${Link(page.gitHubURL, page.sharedPath)}
${CreatePageLink(
page.translations[lang]?.gitHostingUrl!,
page.translations[lang]?.gitHubURL!,
dashboard.ui['statusByLocale.createFileLink']
)}
</li>
Expand Down Expand Up @@ -206,7 +206,7 @@ export const TableBody = (
(page) =>
html`
<tr>
<td>${GitHostingLink(page.gitHostingUrl, page.sharedPath)}</td>
<td>${Link(page.gitHubURL, page.sharedPath)}</td>
${locales.map(({ lang }) => {
return TableContentStatus(page.translations, lang, dashboard);
})}
Expand All @@ -229,12 +229,10 @@ export const TableContentStatus = (
><span aria-hidden="true">${dashboard.ui['status.emojiMissing']}</span></span
>`
: translations[lang]?.isOutdated || !translations[lang]?.completeness.complete
? html`<a
href="${translations[lang]?.gitHostingUrl}"
title="${dashboard.ui['status.outdated']}"
? html`<a href="${translations[lang]?.gitHubURL}" title="${dashboard.ui['status.outdated']}"
><span aria-hidden="true">${dashboard.ui['status.emojiOutdated']}</span></a
>`
: html`<a href="${translations[lang]?.gitHostingUrl}" title="${dashboard.ui['status.done']}"
: html`<a href="${translations[lang]?.gitHubURL}" title="${dashboard.ui['status.done']}"
><span aria-hidden="true">${dashboard.ui['status.emojiDone']}</span></a
>`}
</td>
Expand All @@ -247,23 +245,23 @@ export const ContentDetailsLinks = (
dashboard: Dashboard
) => {
return html`
${GitHostingLink(page.gitHostingUrl, page.sharedPath)}
${Link(page.gitHubURL, page.sharedPath)}
${page.translations[lang]
? html`(${GitHostingLink(
page.translations[lang]?.gitHostingUrl!,
? html`(${Link(
page.translations[lang]?.gitHubURL!,
!page.translations[lang]?.completeness.complete
? dashboard.ui['statusByLocale.incompleteTranslationLink']
: dashboard.ui['statusByLocale.outdatedTranslationLink']
)},
${GitHostingLink(
page.translations[lang]?.sourceHistoryUrl!,
${Link(
page.translations[lang]?.sourceHistoryURL!,
dashboard.ui['statusByLocale.sourceChangeHistoryLink']
)})`
: ''}
`;
};

export const GitHostingLink = (href: string, text: string) => {
export const Link = (href: string, text: string) => {
return html`<a href="${href}">${text}</a>`;
};

Expand Down
11 changes: 4 additions & 7 deletions packages/core/src/schemas/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ export const LunariaConfigSchema = z.object({
sharedPathResolver: SharedPathResolverSchema,
/** Fuction to construct the locale-specific path from the source path of the same content. */
localePathConstructor: LocalePathConstructorSchema,
/** The URL of your current repository, used to generate history links, e.g. `"https://github.com/Yan-Thomas/lunaria"`. */
/** The URL of your current repository, used to generate history links, e.g. `"https://github.com/Yan-Thomas/lunaria/"`. */
repository: z
.string()
.url()
.refine(
(url) => url.startsWith('https://github.com/') || url.startsWith('https://gitlab.com/'),
{
message: 'URL needs to be a valid `"https://github.com/"` or `"https://gitlab.com/"` link.',
}
)
.refine((url) => url.startsWith('https://github.com/'), {
message: 'URL needs to be a valid GitHub link (`"https://github.com/"`).',
})
.transform((url) => normalizeURL(url))
.describe(
'The URL of your current repository, used to generate history links, e.g. `"https://github.com/Yan-Thomas/lunaria/"`.'
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getPageHistory } from './utils/git.js';
import {
getFrontmatterFromFile,
getFrontmatterProperty,
getGitHostingURL,
getGitHubURL,
loadFile,
renderToString,
toUtcString,
Expand Down Expand Up @@ -55,7 +55,7 @@ export async function getTranslationStatus(
const fileStatus: FileTranslationStatus = {
sharedPath,
sourcePage: sourceFile,
gitHostingUrl: getGitHostingURL({
gitHubURL: getGitHubURL({
repository: repository,
rootDir: rootDir,
filePath: sourceFile.filePath,
Expand All @@ -73,13 +73,13 @@ export async function getTranslationStatus(
sourcePath: sourceFile.filePath,
});

const existingPageURL = getGitHostingURL({
const existingPageURL = getGitHubURL({
repository: repository,
rootDir: rootDir,
filePath: localeFilePath,
});

const missingPageURL = getGitHostingURL({
const missingPageURL = getGitHubURL({
repository: repository,
rootDir: rootDir,
type: 'new',
Expand All @@ -98,8 +98,8 @@ export async function getTranslationStatus(
isOutdated:
(translationFile && sourceFile.lastMajorChange > translationFile.lastMajorChange) ??
false,
gitHostingUrl: !translationFile ? missingPageURL : existingPageURL,
sourceHistoryUrl: getGitHostingURL({
gitHubURL: !translationFile ? missingPageURL : existingPageURL,
sourceHistoryURL: getGitHubURL({
repository: repository,
rootDir: rootDir,
filePath: sourceFile.filePath,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type FileData = {
lastMajorCommitMessage: string;
};

export type GitHostingURL = {
export type GitHubURL = {
type?: string;
refName?: string;
query?: string;
Expand All @@ -50,7 +50,7 @@ export type GitHostingURL = {
export type FileTranslationStatus = {
sharedPath: string;
sourcePage: FileData;
gitHostingUrl: string;
gitHubURL: string;
translations: {
[locale: string]: TranslationStatus;
};
Expand All @@ -64,8 +64,8 @@ export type TranslationStatus = {
};
isMissing: boolean;
isOutdated: boolean;
gitHostingUrl: string;
sourceHistoryUrl: string;
gitHubURL: string;
sourceHistoryURL: string;
};

export type RegExpGroups<T extends string> =
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { extname } from 'node:path';
import { joinURL } from 'ufo';
import { parse } from 'ultramatter';
import { frontmatterFileExtensions } from '../constants.js';
import type { GitHostingURL } from '../types.js';
import type { GitHubURL } from '../types.js';

export function renderToString(data: any) {
const { strings, values } = data;
Expand Down Expand Up @@ -66,13 +66,13 @@ export const loadFile = jiti(process.cwd(), {
esmResolve: true,
});

export function getGitHostingURL({
export function getGitHubURL({
type = 'blob',
refName = 'main',
query = '',
repository,
rootDir,
filePath = '',
}: GitHostingURL) {
}: GitHubURL) {
return joinURL(repository, type, refName, rootDir, filePath, query);
}

0 comments on commit 99e4ee6

Please sign in to comment.