Skip to content

Commit

Permalink
fix: support string in shareKey
Browse files Browse the repository at this point in the history
Now, the key is converted to string, and the value accepted are:
- `1`
- `true`
- `yes`

Fix #225
  • Loading branch information
Mara-Li committed Sep 25, 2023
1 parent eb14a7f commit 1fe71c5
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/utils/data_validation_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {FrontmatterConvert, GitHubPublisherSettings, MultiProperties, RepoFrontm
import {getRepoFrontmatter, logs, notif} from ".";

/**
* Check if the file is a valid file to publish
* Check also the path from the excluded folder list
* Always return false if the internalNonShared is not enabled
* - Check if the file is a valid file to publish
* - Check also the path from the excluded folder list
* - Always return false if the internalNonShared is not enabled
* - Return true for all files that are not shared, unless they are striclty excluded (share: false or folder excluded)
* @param {FrontMatterCache} frontmatter
* @param {MultiProperties} properties
* @param {TFile} file (for the excluded file name & filepath)
Expand All @@ -22,17 +23,18 @@ export function isInternalShared(
file: TFile,
): boolean {
const frontmatterSettings = properties.frontmatter.general;

if (!frontmatterSettings.convertInternalNonShared) return false;
if (properties.repository?.shareAll?.enable) {
if (properties.repository?.shareAll?.enable)
{
const excludedFileName = properties.repository.shareAll.excludedFileName;
return !file.basename.startsWith(excludedFileName);
}
if (!frontmatter) return true;
if (isExcludedPath(properties.settings, file)) return false;
const shareKey = properties.repository?.shareKey || properties.settings.plugin.shareKey;
if (frontmatter[shareKey] === undefined) return true;
return frontmatter[shareKey];
return ["true", "1", "yes"].includes(frontmatter[shareKey].toString().toLowerCase());
}

export function getRepoSharedKey(settings: GitHubPublisherSettings, frontmatter?: FrontMatterCache): Repository | null{
Expand All @@ -51,7 +53,9 @@ export function getRepoSharedKey(settings: GitHubPublisherSettings, frontmatter?
}

/**
* Disable publishing if the file hasn't a valid frontmatter or if the file is in the folder list to ignore
* - Disable publishing if the file hasn't a valid frontmatter or if the file is in the folder list to ignore
* - Check if the file is in the excluded file list
* - Verify for all Repository if the file is shared
* @param {FrontMatterCache} meta the frontmatter of the file
* @param {GitHubPublisherSettings} settings
* @param {TFile} file
Expand All @@ -73,7 +77,9 @@ export function isShared(
const shareKey = otherRepo ? otherRepo.shareKey : settings.plugin.shareKey;
if ( meta == null || meta[shareKey] === undefined || isExcludedPath(settings, file)) {
return false;
} return meta[shareKey];
}
const shareKeyInFrontmatter = meta[shareKey].toString().toLowerCase();
return ["true", "1", "yes"].includes(shareKeyInFrontmatter);
} else if (settings.plugin.shareAll?.enable || otherRepoWithShareAll.length > 0) {
const allExcludedFileName = otherRepoWithShareAll.map((repo) => repo.shareAll!.excludedFileName);
allExcludedFileName.push(settings.plugin.shareAll!.excludedFileName);
Expand Down Expand Up @@ -109,7 +115,7 @@ export function multipleSharedKey(frontmatter: FrontMatterCache | undefined, set
const keysInFile: string[] = [];
if (settings.plugin.shareAll?.enable)
keysInFile.push("share"); //add a key to count the shareAll

const otherRepoWithShareAll = settings.github.otherRepo.filter((repo) => repo.shareAll);
if (otherRepoWithShareAll.length > 0) {
for (const repo of otherRepoWithShareAll) {
Expand All @@ -119,7 +125,7 @@ export function multipleSharedKey(frontmatter: FrontMatterCache | undefined, set
if (!frontmatter) return keysInFile;
const allKey = settings.github.otherRepo.map((repo) => repo.shareKey);
allKey.push(settings.plugin.shareKey);

for (const key of allKey) {
if (frontmatter[key]) {
keysInFile.push(key);
Expand Down

0 comments on commit 1fe71c5

Please sign in to comment.