add support for writing back url into frontmatter after publish
This commit is contained in:
parent
808c190a77
commit
c14c231d34
|
@ -1,14 +1,16 @@
|
||||||
import { ErrorView } from '@views/ErrorView'
|
import { ErrorView } from '@views/ErrorView'
|
||||||
import { Notice, Plugin } from 'obsidian'
|
import { Editor, Notice, Plugin } from 'obsidian'
|
||||||
import { MicroPluginContainerInterface, MicroPluginContainer } from '@base/MicroPluginContainer'
|
import { MicroPluginContainerInterface, MicroPluginContainer } from '@base/MicroPluginContainer'
|
||||||
import { MicroPluginSettingsView } from '@views/MicroPluginSettingsView'
|
import { MicroPluginSettingsView } from '@views/MicroPluginSettingsView'
|
||||||
import { PublishView } from '@views/PublishView'
|
import { PublishView } from '@views/PublishView'
|
||||||
import { ServiceFactory, ServiceFactoryInterface } from '@factories/ServiceFactory'
|
import { ServiceFactory, ServiceFactoryInterface } from '@factories/ServiceFactory'
|
||||||
import { StoredSettings, defaultSettings } from '@stores/StoredSettings'
|
import { StoredSettings, defaultSettings } from '@stores/StoredSettings'
|
||||||
import { TagSynchronizationServiceInterface } from '@services/TagSynchronizationService'
|
import { TagSynchronizationServiceDelegate, TagSynchronizationServiceInterface } from '@services/TagSynchronizationService'
|
||||||
import { ViewModelFactoryInterface, ViewModelFactory } from '@factories/ViewModelFactory'
|
import { ViewModelFactoryInterface, ViewModelFactory } from '@factories/ViewModelFactory'
|
||||||
|
import { FrontmatterServiceDelegate, FrontmatterServiceInterface } from './services/FrontmatterService'
|
||||||
|
import { PublishResponse } from './networking/PublishResponse'
|
||||||
|
|
||||||
export default class MicroPlugin extends Plugin {
|
export default class MicroPlugin extends Plugin implements TagSynchronizationServiceDelegate {
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
|
|
||||||
|
@ -17,15 +19,17 @@ export default class MicroPlugin extends Plugin {
|
||||||
private viewModelFactory: ViewModelFactoryInterface
|
private viewModelFactory: ViewModelFactoryInterface
|
||||||
private serviceFactory: ServiceFactoryInterface
|
private serviceFactory: ServiceFactoryInterface
|
||||||
private synchronizationService: TagSynchronizationServiceInterface
|
private synchronizationService: TagSynchronizationServiceInterface
|
||||||
|
private frontmatterService: FrontmatterServiceInterface
|
||||||
|
|
||||||
// Public
|
// Public
|
||||||
|
|
||||||
public async onload() {
|
public async onload() {
|
||||||
await this.loadSettings()
|
await this.loadSettings()
|
||||||
await this.loadDependencies()
|
await this.loadDependencies()
|
||||||
await this.loadViewModelFactory()
|
|
||||||
await this.loadServiceFactory()
|
await this.loadServiceFactory()
|
||||||
await this.registerSynchronizationService()
|
await this.registerSynchronizationService()
|
||||||
|
await this.registerFrontmatterService()
|
||||||
|
await this.loadViewModelFactory()
|
||||||
|
|
||||||
this.synchronizationService.fetchTags()
|
this.synchronizationService.fetchTags()
|
||||||
|
|
||||||
|
@ -41,7 +45,8 @@ export default class MicroPlugin extends Plugin {
|
||||||
new PublishView(
|
new PublishView(
|
||||||
this.viewModelFactory.makePublishViewModel(
|
this.viewModelFactory.makePublishViewModel(
|
||||||
markdownView.file.basename,
|
markdownView.file.basename,
|
||||||
editor.getValue()
|
editor.getValue(),
|
||||||
|
editor
|
||||||
)
|
)
|
||||||
).open()
|
).open()
|
||||||
}
|
}
|
||||||
|
@ -88,7 +93,8 @@ export default class MicroPlugin extends Plugin {
|
||||||
|
|
||||||
private async loadViewModelFactory() {
|
private async loadViewModelFactory() {
|
||||||
this.viewModelFactory = new ViewModelFactory(
|
this.viewModelFactory = new ViewModelFactory(
|
||||||
this.container
|
this.container,
|
||||||
|
this.frontmatterService
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +111,11 @@ export default class MicroPlugin extends Plugin {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async registerFrontmatterService() {
|
||||||
|
this.frontmatterService = this.serviceFactory
|
||||||
|
.makeFrontmatterService()
|
||||||
|
}
|
||||||
|
|
||||||
// TagSynchronizationServiceDelegate
|
// TagSynchronizationServiceDelegate
|
||||||
|
|
||||||
public tagSynchronizationDidSucceed(
|
public tagSynchronizationDidSucceed(
|
||||||
|
|
|
@ -17,6 +17,7 @@ export interface MicroPluginContainerInterface {
|
||||||
// The network request factory, used to build the
|
// The network request factory, used to build the
|
||||||
// requests which will be executed by the network client.
|
// requests which will be executed by the network client.
|
||||||
networkRequestFactory: NetworkRequestFactoryInterface
|
networkRequestFactory: NetworkRequestFactoryInterface
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MicroPluginContainer implements MicroPluginContainerInterface {
|
export class MicroPluginContainer implements MicroPluginContainerInterface {
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
import { MicroPluginContainerInterface } from "@base/MicroPluginContainer";
|
import { MicroPluginContainerInterface } from "@base/MicroPluginContainer";
|
||||||
|
import {
|
||||||
|
FrontmatterService,
|
||||||
|
FrontmatterServiceInterface,
|
||||||
|
FrontmatterServiceDelegate } from "@base/services/FrontmatterService";
|
||||||
import {
|
import {
|
||||||
TagSynchronizationServiceInterface,
|
TagSynchronizationServiceInterface,
|
||||||
TagSynchronizationService,
|
TagSynchronizationService,
|
||||||
|
@ -13,6 +17,13 @@ export interface ServiceFactoryInterface {
|
||||||
makeTagSynchronizationService(
|
makeTagSynchronizationService(
|
||||||
delegate?: TagSynchronizationServiceDelegate
|
delegate?: TagSynchronizationServiceDelegate
|
||||||
): TagSynchronizationServiceInterface
|
): TagSynchronizationServiceInterface
|
||||||
|
|
||||||
|
// Builds the yaml frontmatter service, used by the client
|
||||||
|
// to update the frontmatter of the file after publishing
|
||||||
|
// with publish date, used tags, etc.
|
||||||
|
makeFrontmatterService(
|
||||||
|
delegate?: FrontmatterServiceDelegate
|
||||||
|
): FrontmatterServiceInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -47,4 +58,12 @@ export class ServiceFactory implements ServiceFactoryInterface {
|
||||||
delegate
|
delegate
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public makeFrontmatterService(
|
||||||
|
delegate?: FrontmatterServiceDelegate
|
||||||
|
): FrontmatterServiceInterface {
|
||||||
|
return new FrontmatterService(
|
||||||
|
delegate
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
import { MicroPluginSettingsViewModel } from '@views/MicroPluginSettingsViewModel'
|
import { MicroPluginSettingsViewModel } from '@views/MicroPluginSettingsViewModel'
|
||||||
import { PublishViewModel } from '@views/PublishViewModel'
|
import { PublishViewModel, PublishViewModelDelegate } from '@views/PublishViewModel'
|
||||||
import { TagSuggestionViewModel, TagSuggestionDelegate } from '@views/TagSuggestionViewModel'
|
import { TagSuggestionViewModel, TagSuggestionDelegate } from '@views/TagSuggestionViewModel'
|
||||||
import { ErrorViewModel } from '@views/ErrorViewModel'
|
import { ErrorViewModel } from '@views/ErrorViewModel'
|
||||||
import { MicroPluginContainerInterface } from '@base/MicroPluginContainer'
|
import { MicroPluginContainerInterface } from '@base/MicroPluginContainer'
|
||||||
|
import { Editor } from 'obsidian'
|
||||||
|
import { ServiceFactoryInterface } from './ServiceFactory'
|
||||||
|
import { FrontmatterServiceInterface } from '@base/services/FrontmatterService'
|
||||||
|
|
||||||
export interface ViewModelFactoryInterface {
|
export interface ViewModelFactoryInterface {
|
||||||
|
|
||||||
|
@ -10,7 +13,9 @@ export interface ViewModelFactoryInterface {
|
||||||
// to Micro.blog via the Commands Palette.
|
// to Micro.blog via the Commands Palette.
|
||||||
makePublishViewModel(
|
makePublishViewModel(
|
||||||
title: string,
|
title: string,
|
||||||
content: string
|
content: string,
|
||||||
|
editor: Editor,
|
||||||
|
delegate?: PublishViewModelDelegate
|
||||||
): PublishViewModel
|
): PublishViewModel
|
||||||
|
|
||||||
// Builds the Plugin Settings View Model, used by the plugin
|
// Builds the Plugin Settings View Model, used by the plugin
|
||||||
|
@ -37,22 +42,26 @@ export class ViewModelFactory implements ViewModelFactoryInterface {
|
||||||
// Properties
|
// Properties
|
||||||
|
|
||||||
private container: MicroPluginContainerInterface
|
private container: MicroPluginContainerInterface
|
||||||
|
private frontmatterService: FrontmatterServiceInterface
|
||||||
|
|
||||||
// Life cycle
|
// Life cycle
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
container: MicroPluginContainerInterface
|
container: MicroPluginContainerInterface,
|
||||||
|
frontmatterService: FrontmatterServiceInterface
|
||||||
) {
|
) {
|
||||||
this.container = container
|
this.container = container
|
||||||
|
this.frontmatterService = frontmatterService
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public
|
// Public
|
||||||
|
|
||||||
public makePublishViewModel(
|
public makePublishViewModel(
|
||||||
title: string,
|
title: string,
|
||||||
content: string
|
content: string,
|
||||||
|
editor: Editor
|
||||||
): PublishViewModel {
|
): PublishViewModel {
|
||||||
return new PublishViewModel(
|
const viewModel = new PublishViewModel(
|
||||||
title,
|
title,
|
||||||
content,
|
content,
|
||||||
this.container.settings.defaultTags,
|
this.container.settings.defaultTags,
|
||||||
|
@ -61,8 +70,12 @@ export class ViewModelFactory implements ViewModelFactoryInterface {
|
||||||
this.container.settings.selectedBlogID,
|
this.container.settings.selectedBlogID,
|
||||||
this.container.networkClient,
|
this.container.networkClient,
|
||||||
this.container.networkRequestFactory,
|
this.container.networkRequestFactory,
|
||||||
this
|
this,
|
||||||
|
this.frontmatterService,
|
||||||
|
editor
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return viewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
public makeMicroPluginSettingsViewModel(): MicroPluginSettingsViewModel {
|
public makeMicroPluginSettingsViewModel(): MicroPluginSettingsViewModel {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { NetworkRequest } from '@networking/NetworkRequest'
|
import { NetworkRequest } from '@networking/NetworkRequest'
|
||||||
|
import { log } from 'console'
|
||||||
|
|
||||||
export interface NetworkRequestFactoryInterface {
|
export interface NetworkRequestFactoryInterface {
|
||||||
|
|
||||||
|
@ -78,8 +79,9 @@ export class NetworkRequestFactory implements NetworkRequestFactoryInterface {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: this.endpointUrl(),
|
url: this.endpointUrl(),
|
||||||
parameters: parameters,
|
parameters: new URLSearchParams(),
|
||||||
method: 'POST'
|
method: 'POST',
|
||||||
|
body: parameters.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,185 @@
|
||||||
|
import { PublishResponse } from "@base/networking/PublishResponse";
|
||||||
|
import { Editor, EditorPosition, parseYaml, stringifyYaml } from "obsidian";
|
||||||
|
|
||||||
|
export const YAML_REGEX = /^---\n(?:((?:.|\n)*?)\n)?---(?=\n|$)/;
|
||||||
|
|
||||||
|
type CommonUpdateParam = {
|
||||||
|
editor: Editor;
|
||||||
|
key: string;
|
||||||
|
value: string;
|
||||||
|
action: 'replace' | 'insert' | 'remove';
|
||||||
|
}
|
||||||
|
|
||||||
|
type BulkUpdateParam = {
|
||||||
|
editor: Editor;
|
||||||
|
updateDatas: Record<string, unknown>;
|
||||||
|
removeDatas: string[];
|
||||||
|
action: 'bulk'
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FrontmatterServiceInterface {
|
||||||
|
updateFrontmatter(response: PublishResponse, editor: Editor): void
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FrontmatterServiceDelegate {
|
||||||
|
frontmatterUpdateDidSucceed(): void
|
||||||
|
|
||||||
|
frontmatterUpdateDidFail(error: Error): void
|
||||||
|
}
|
||||||
|
|
||||||
|
export class FrontmatterService implements FrontmatterServiceInterface {
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
|
||||||
|
private delegate?: FrontmatterServiceDelegate
|
||||||
|
|
||||||
|
// Life cycle
|
||||||
|
|
||||||
|
constructor(delegate?: FrontmatterServiceDelegate) {
|
||||||
|
this.delegate = delegate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public
|
||||||
|
|
||||||
|
public async updateFrontmatter(response: PublishResponse, editor: Editor) {
|
||||||
|
const yaml = this.getObjectYaml(editor)
|
||||||
|
|
||||||
|
this.upsert("url", response.url, false, editor)
|
||||||
|
this.delegate?.frontmatterUpdateDidSucceed()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Get objectify yaml of current file
|
||||||
|
getObjectYaml(editor: Editor) {
|
||||||
|
const stringYaml = this.getYaml(editor);
|
||||||
|
|
||||||
|
return stringYaml? parseYaml(stringYaml.slice(4, -4)): {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exchange item position in array
|
||||||
|
itemMove<T>(arr: T[], itemIdx1: number, itemIdx2: number): void {
|
||||||
|
[arr[itemIdx1], arr[itemIdx2]] = [arr[itemIdx2], arr[itemIdx1]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add item in specific position
|
||||||
|
itemAdd<T>(arr: T[], itemIdx: number, item: T): void {
|
||||||
|
arr.splice(itemIdx, 0, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete specific item in array
|
||||||
|
itemDelete<T>(arr: T[], itemIndex: number): void {
|
||||||
|
arr.splice(itemIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get yaml section
|
||||||
|
getYaml(editor: Editor): string {
|
||||||
|
const matchResult = editor.getValue().match(YAML_REGEX);
|
||||||
|
|
||||||
|
return matchResult?.[0] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
generateActionKeyword(data: CommonUpdateParam | BulkUpdateParam) {
|
||||||
|
const {editor, action} = data;
|
||||||
|
const yamlSection = this.getYaml(editor);
|
||||||
|
const yaml = yamlSection.slice(4, -3);
|
||||||
|
const objectYaml = this.getObjectYaml(editor);
|
||||||
|
const objectSnippet: Record<string, unknown> = {};
|
||||||
|
|
||||||
|
if (action === 'replace') objectSnippet[data.key] = data.value;
|
||||||
|
|
||||||
|
if (action === 'insert') {
|
||||||
|
if (objectYaml[data.key] instanceof Array) {
|
||||||
|
console.log('inserting into array')
|
||||||
|
objectSnippet[data.key] = [...objectYaml[data.key], data.value];
|
||||||
|
} else {
|
||||||
|
console.log('inserting')
|
||||||
|
//objectSnippet[data.key] = [data.value];
|
||||||
|
objectSnippet[data.key] = data.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (action === 'remove') {
|
||||||
|
if (objectYaml[data.key] instanceof Array) {
|
||||||
|
const newValue = objectYaml[data.key].filter((val: string) => val !== data.value);
|
||||||
|
objectSnippet[data.key] = newValue.length? newValue: null;
|
||||||
|
} else {
|
||||||
|
objectSnippet[data.key] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action === 'bulk') {
|
||||||
|
Object.entries(data.updateDatas).forEach(([key, value]) => objectSnippet[key] = value );
|
||||||
|
data.removeDatas.forEach((key) => objectSnippet[key] = null)
|
||||||
|
}
|
||||||
|
|
||||||
|
let replacement = `---\n${this.generateReplacement(yaml, objectSnippet)}---`;
|
||||||
|
const startPosition: EditorPosition = {line: 0, ch: 0};
|
||||||
|
const endPosition: EditorPosition = editor.offsetToPos(yamlSection.length);
|
||||||
|
|
||||||
|
// Make sure there is at least one newline character
|
||||||
|
// after the end of the frontmatter
|
||||||
|
const charAfterYaml = editor.getRange(endPosition, {ch: endPosition.ch + 1, line: endPosition.line})
|
||||||
|
replacement = charAfterYaml == "\n" ? replacement : replacement + "\n"
|
||||||
|
|
||||||
|
return {replacement, startPosition, endPosition}
|
||||||
|
}
|
||||||
|
|
||||||
|
generateReplacement(yaml: string, snippet: Record<string, unknown>) {
|
||||||
|
return Object.entries(snippet).reduce((temp, [key, value]) => {
|
||||||
|
const YAML_FIELD_REGEX = new RegExp(`(${key} *:).+?\\n(?=\\S|$)`, 'gs');
|
||||||
|
|
||||||
|
const replacement = (value === null)? '': stringifyYaml({[key]: value});
|
||||||
|
|
||||||
|
return temp.match(YAML_FIELD_REGEX)? temp.replace(YAML_FIELD_REGEX, replacement): `${temp}${replacement}`;
|
||||||
|
}, yaml)
|
||||||
|
}
|
||||||
|
|
||||||
|
flatYamlFields(yaml: string, flatFields: string[]): string {
|
||||||
|
const objectYaml = parseYaml(yaml.slice(4, -4));
|
||||||
|
|
||||||
|
return flatFields.reduce((temp, key) => {
|
||||||
|
const YAML_FIELD_REGEX = new RegExp(`(${key}:).+?(?=\\n\\S|$)`, 'gs');
|
||||||
|
|
||||||
|
return temp.match(YAML_FIELD_REGEX)? temp.replace(YAML_FIELD_REGEX, `$1 [${objectYaml[key].join(', ')}]`): temp;
|
||||||
|
}, yaml)
|
||||||
|
}
|
||||||
|
|
||||||
|
replace(key: string, value: string, editor: Editor): void {
|
||||||
|
const {replacement, startPosition, endPosition} = this.generateActionKeyword({key, value, editor, action: 'replace'});
|
||||||
|
|
||||||
|
editor.replaceRange(replacement, startPosition, endPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
insert(key: string, value: string, flat: boolean, editor: Editor): void {
|
||||||
|
const {replacement, startPosition, endPosition} = this.generateActionKeyword({key, value, editor, action: 'insert'});
|
||||||
|
|
||||||
|
const postProcessedReplacement = flat? this.flatYamlFields(replacement, [key]): replacement;
|
||||||
|
|
||||||
|
editor.replaceRange(postProcessedReplacement, startPosition, endPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
upsert(key: string, value: string, flat: boolean, editor: Editor): void {
|
||||||
|
const yaml = this.getObjectYaml(editor)
|
||||||
|
|
||||||
|
if (yaml[key]) {
|
||||||
|
this.replace(key, value, editor)
|
||||||
|
} else {
|
||||||
|
this.insert(key, value, flat, editor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(key: string, value: string, flat: boolean, editor: Editor): void {
|
||||||
|
const {replacement, startPosition, endPosition} = this.generateActionKeyword({key, value, editor, action: 'remove'});
|
||||||
|
|
||||||
|
const postProcessedReplacement = flat? this.flatYamlFields(replacement, [key]): replacement;
|
||||||
|
|
||||||
|
editor.replaceRange(postProcessedReplacement, startPosition, endPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
bulkUpdate(updateDatas: Record<string, unknown>, removeDatas: string[], flatFields: string[], editor: Editor): void {
|
||||||
|
const {replacement, startPosition, endPosition} = this.generateActionKeyword({updateDatas, removeDatas, editor, action: 'bulk'});
|
||||||
|
|
||||||
|
const flattedReplacement = this.flatYamlFields(replacement, flatFields);
|
||||||
|
|
||||||
|
editor.replaceRange(flattedReplacement, startPosition, endPosition);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,9 @@ import { NetworkClientInterface } from '@networking/NetworkClient'
|
||||||
import { PublishResponse } from '@networking/PublishResponse'
|
import { PublishResponse } from '@networking/PublishResponse'
|
||||||
import { TagSuggestionDelegate, TagSuggestionViewModel } from '@views/TagSuggestionViewModel'
|
import { TagSuggestionDelegate, TagSuggestionViewModel } from '@views/TagSuggestionViewModel'
|
||||||
import { ViewModelFactoryInterface } from '@factories/ViewModelFactory'
|
import { ViewModelFactoryInterface } from '@factories/ViewModelFactory'
|
||||||
|
import { Editor } from 'obsidian'
|
||||||
|
import { ServiceFactoryInterface } from '@base/factories/ServiceFactory'
|
||||||
|
import { FrontmatterService, FrontmatterServiceInterface } from '@base/services/FrontmatterService'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Publish View Delegate Interface, implemented by
|
* Publish View Delegate Interface, implemented by
|
||||||
|
@ -53,6 +56,8 @@ export class PublishViewModel implements TagSuggestionDelegate {
|
||||||
private networkClient: NetworkClientInterface
|
private networkClient: NetworkClientInterface
|
||||||
private networkRequestFactory: NetworkRequestFactoryInterface
|
private networkRequestFactory: NetworkRequestFactoryInterface
|
||||||
private viewModelFactory: ViewModelFactoryInterface
|
private viewModelFactory: ViewModelFactoryInterface
|
||||||
|
private frontmatterService: FrontmatterServiceInterface
|
||||||
|
private editor: Editor
|
||||||
readonly blogs: Record<string, string>
|
readonly blogs: Record<string, string>
|
||||||
|
|
||||||
// Life cycle
|
// Life cycle
|
||||||
|
@ -66,7 +71,9 @@ export class PublishViewModel implements TagSuggestionDelegate {
|
||||||
selectedBlogID: string,
|
selectedBlogID: string,
|
||||||
networkClient: NetworkClientInterface,
|
networkClient: NetworkClientInterface,
|
||||||
networkRequestFactory: NetworkRequestFactoryInterface,
|
networkRequestFactory: NetworkRequestFactoryInterface,
|
||||||
viewModelFactory: ViewModelFactoryInterface
|
viewModelFactory: ViewModelFactoryInterface,
|
||||||
|
frontmatterService: FrontmatterServiceInterface,
|
||||||
|
editor: Editor
|
||||||
) {
|
) {
|
||||||
this.titleWrappedValue = title
|
this.titleWrappedValue = title
|
||||||
this.content = content
|
this.content = content
|
||||||
|
@ -80,6 +87,8 @@ export class PublishViewModel implements TagSuggestionDelegate {
|
||||||
this.networkClient = networkClient
|
this.networkClient = networkClient
|
||||||
this.networkRequestFactory = networkRequestFactory
|
this.networkRequestFactory = networkRequestFactory
|
||||||
this.viewModelFactory = viewModelFactory
|
this.viewModelFactory = viewModelFactory
|
||||||
|
this.frontmatterService = frontmatterService
|
||||||
|
this.editor = editor
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public
|
// Public
|
||||||
|
@ -162,6 +171,8 @@ export class PublishViewModel implements TagSuggestionDelegate {
|
||||||
request
|
request
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.frontmatterService.updateFrontmatter(response, this.editor)
|
||||||
|
|
||||||
this.delegate?.publishDidSucceed(response)
|
this.delegate?.publishDidSucceed(response)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.delegate?.publishDidFail(error)
|
this.delegate?.publishDidFail(error)
|
||||||
|
|
Loading…
Reference in New Issue