Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #437

Merged
merged 17 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions README.md

This file was deleted.

29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# wikiGDrive

Google Drive to MarkDown synchronization

[![Develop Server Deploy](https://github.com/mieweb/wikiGDrive/actions/workflows/DevelopServerDeploy.yml/badge.svg?branch=develop&event=push)](https://github.com/mieweb/wikiGDrive/actions/workflows/DevelopServerDeploy.yml)
[![Prod Server Deploy](https://github.com/mieweb/wikiGDrive/actions/workflows/ProdServerDeploy.yml/badge.svg?branch=master&event=push)](https://github.com/mieweb/wikiGDrive/actions/workflows/ProdServerDeploy.yml)
[![CodeQL](https://github.com/mieweb/wikiGDrive/actions/workflows/codeql-analysis.yml/badge.svg?branch=master&event=push)](https://github.com/mieweb/wikiGDrive/actions/workflows/codeql-analysis.yml?query=event%3Apush+branch%3Amaster+)

WikiGDrive is a node app that uses the [Google Drive API](https://developers.google.com/drive/api/v3/quickstart/nodejs) to transform Google Docs and Drawings into markdown.

With a "Shared Drive" as the key, WikiGDrive:

* Reads all the files from a Google "Shared Drive"
* Builds a map of the driveId (URL) to the pathname in the "Shared Drive"
* For each Google Document:
* Converts to a Markdown file with the path (instead of the driveId for the file)
* Changes driveId to the path (eg: 12lvdxKgGsD.../edit would be changed to /filename
* Support diagrams as SVG (and map the URLs in the diagram)

WikiGDrive scans for changes in the drive and then refresh the local converted files.

## Usage

* [Usage](./website/docs/usage/wikigdrive-usage.md)

## Developer Documentation

* [Developer README](./website/docs/developer-guide.md)
* [Internals](./website/docs/internals.md)
4 changes: 2 additions & 2 deletions apps/ui/src/components/PreviewHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ export default {
}

const folderPath = this.folderPath.endsWith('/') ? this.folderPath : this.folderPath + '/';
const filePath = folderPath + this.selectedFile.fileName;
const filePaths = folderPath + this.selectedFile.fileName;

await this.commit({
message: this.commitMsg,
filePath
filePaths
});
this.commitMsg = '';
},
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/pages/GDocsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ export default {
}

const folderPath = this.folderPath.endsWith('/') ? this.folderPath : this.folderPath + '/';
const filePath = folderPath + this.selectedFile.fileName;
const filePaths = folderPath + this.selectedFile.fileName;

await this.commit({
message: this.commitMsg,
filePath
filePaths
});
this.commitMsg = '';
return true;
Expand Down
31 changes: 27 additions & 4 deletions src/cli/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ function locateUsage(usageMarkdown: string, sectionPrefix: string): string {
return retVal.join('\n');
}

function indentMarkdownCodes(markdown: string) {
const retVal = [];

const lines = markdown.split('\n');
let inCode = false;
for (const line of lines) {
if (line === '```') {
inCode = !inCode;
continue;
}

if (inCode) {
retVal.push(' ' + line);
} else {
retVal.push(line);
}
}

return retVal.join('\n');
}

export async function usage(filename: string) {
const pkg = JSON.parse(new TextDecoder().decode(fs.readFileSync(path.resolve(__dirname, '..', '..', 'package.json'))));

Expand All @@ -38,13 +59,15 @@ export async function usage(filename: string) {
const sectionName = filename.replace(/^.*-(.*).ts/, '$1');


const mdFilename = execName + '_usage.md';
const mdFilename = execName + '-usage.md';

const usageMarkdown = new TextDecoder().decode(fs.readFileSync(path.resolve(__dirname, '..', '..', 'website', 'docs', 'usage', mdFilename)));

const commandUsage = locateUsage(usageMarkdown, `${execName} ${sectionName}`) || locateUsage(usageMarkdown, `${execName} usage`);
const allCommands = locateUsage(usageMarkdown, 'All commands');
const commonOptions = locateUsage(usageMarkdown, 'Common options');
const indentedMarkdown = indentMarkdownCodes(usageMarkdown);

const commandUsage = locateUsage(indentedMarkdown, `${execName} ${sectionName}`) || locateUsage(indentedMarkdown, `${execName} usage`);
const allCommands = locateUsage(indentedMarkdown, 'All commands');
const commonOptions = locateUsage(indentedMarkdown, 'Common options');

console.log(
`${pkg.name} version: ${pkg.version}, ${process.env.GIT_SHA}\n\nUsage:\n${commandUsage.trim()}\n\n${commonOptions.trim()}\n\n${allCommands.trim()}`);
Expand Down
13 changes: 0 additions & 13 deletions src/containers/transform/LocalLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,4 @@ export class LocalLog {
return originalLength !== this.rows.length;
}

async getDirFiles(prefix: string): Promise<LogRow[]> {
const list = this.rows
.filter(row => row.filePath.startsWith(prefix) && row.filePath.substring(prefix.length).indexOf('/') === -1)
.filter(row => row.type === 'md');

const lastOnes: {[key: string]: LogRow} = {};
for (const item of list) {
lastOnes[item.filePath] = item;
}

return Object.values(lastOnes).filter(item => item.event !== 'removed');
}

}
16 changes: 0 additions & 16 deletions src/containers/transform/TransformContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,20 +558,4 @@ export class TransformContainer extends Container {
onProgressNotify(callback: ({total, completed, warnings, failed}: { total?: number; completed?: number, warnings?: number, failed?: number }) => void) {
this.progressNotifyCallback = callback;
}

async removeOutdatedLogEntries(destinationDirectory: FileContentService, destinationFiles: LocalFileMap) {
const prefix = destinationDirectory.getVirtualPath();
const logFiles = await this.localLog.getDirFiles(prefix);
for (const logEntry of logFiles) {
const fileName = logEntry.filePath.substring(prefix.length);
if (!destinationFiles[fileName]) {
this.localLog.append({
filePath: logEntry.filePath,
id: logEntry.id,
type: logEntry.type,
event: 'removed',
});
}
}
}
}
2 changes: 1 addition & 1 deletion src/odt/MarkdownChunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type TAG = 'HR/' | 'BR/' | 'B' | '/B' | 'I' | '/I' | 'BI' | '/BI' |
'TOC' | '/TOC' | 'SVG/' | 'IMG/' |
'EMB_SVG' | '/EMB_SVG' | 'EMB_SVG_G' | '/EMB_SVG_G' | 'EMB_SVG_P/' | 'EMB_SVG_TEXT' | '/EMB_SVG_TEXT' |
'EMB_SVG_TSPAN' | '/EMB_SVG_TSPAN' |
'CHANGE' | '/CHANGE' | 'HTML_MODE/' | 'MD_MODE/';
'CHANGE' | '/CHANGE' | 'HTML_MODE/' | 'MD_MODE/' | 'COMMENT';

export const isOpening = (tag: TAG) => !tag.startsWith('/') && !tag.endsWith('/');
export const isClosing = (tag: TAG) => tag.startsWith('/');
Expand Down
4 changes: 3 additions & 1 deletion src/odt/OdtToMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {inchesToPixels, inchesToSpaces, spaces} from './utils.ts';
import {extractPath} from './extractPath.ts';
import {mergeDeep} from './mergeDeep.ts';
import {RewriteRule} from './applyRewriteRule.ts';
import {postProcessText} from './postprocess/postProcessText.js';

function getBaseFileName(fileName) {
return fileName.replace(/.*\//, '');
Expand Down Expand Up @@ -120,7 +121,8 @@ export class OdtToMarkdown {

const markdown = this.chunks.toString(this.rewriteRules);
const trimmed = this.trimBreaks(markdown);
return await this.rewriteHeaders(trimmed);
const rewrittenHeaders = await this.rewriteHeaders(trimmed);
return postProcessText(rewrittenHeaders);
}

trimBreaks(markdown: string) {
Expand Down
Loading
Loading