mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 14:44:43 -04:00
Move frontmatter types (#1664)
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
8a23aa1401
commit
b68a55aa94
22 changed files with 157 additions and 144 deletions
|
@ -14,11 +14,11 @@ import { EditorViewMode } from './editor-view-mode'
|
||||||
import { HelpButton } from './help-button/help-button'
|
import { HelpButton } from './help-button/help-button'
|
||||||
import { NavbarBranding } from './navbar-branding'
|
import { NavbarBranding } from './navbar-branding'
|
||||||
import { SyncScrollButtons } from './sync-scroll-buttons/sync-scroll-buttons'
|
import { SyncScrollButtons } from './sync-scroll-buttons/sync-scroll-buttons'
|
||||||
import { NoteType } from '../../common/note-frontmatter/types'
|
|
||||||
import { SlideModeButton } from './slide-mode-button'
|
import { SlideModeButton } from './slide-mode-button'
|
||||||
import { ReadOnlyModeButton } from './read-only-mode-button'
|
import { ReadOnlyModeButton } from './read-only-mode-button'
|
||||||
import { NewNoteButton } from './new-note-button'
|
import { NewNoteButton } from './new-note-button'
|
||||||
import { useApplicationState } from '../../../hooks/common/use-application-state'
|
import { useApplicationState } from '../../../hooks/common/use-application-state'
|
||||||
|
import { NoteType } from '../../../redux/note-details/types/note-details'
|
||||||
|
|
||||||
export enum AppBarMode {
|
export enum AppBarMode {
|
||||||
BASIC,
|
BASIC,
|
||||||
|
|
|
@ -14,8 +14,8 @@ import type { ModalVisibilityProps } from '../../../common/modals/common-modal'
|
||||||
import { CommonModal } from '../../../common/modals/common-modal'
|
import { CommonModal } from '../../../common/modals/common-modal'
|
||||||
import { ShowIf } from '../../../common/show-if/show-if'
|
import { ShowIf } from '../../../common/show-if/show-if'
|
||||||
import type { EditorPagePathParams } from '../../editor-page'
|
import type { EditorPagePathParams } from '../../editor-page'
|
||||||
import { NoteType } from '../../../common/note-frontmatter/types'
|
|
||||||
import { useApplicationState } from '../../../../hooks/common/use-application-state'
|
import { useApplicationState } from '../../../../hooks/common/use-application-state'
|
||||||
|
import { NoteType } from '../../../../redux/note-details/types/note-details'
|
||||||
|
|
||||||
export const ShareModal: React.FC<ModalVisibilityProps> = ({ show, onHide }) => {
|
export const ShareModal: React.FC<ModalVisibilityProps> = ({ show, onHide }) => {
|
||||||
useTranslation()
|
useTranslation()
|
||||||
|
@ -37,7 +37,7 @@ export const ShareModal: React.FC<ModalVisibilityProps> = ({ show, onHide }) =>
|
||||||
<Trans i18nKey={'editor.modal.shareLink.slidesDescription'} />
|
<Trans i18nKey={'editor.modal.shareLink.slidesDescription'} />
|
||||||
<CopyableField content={`${baseUrl}p/${id}`} nativeShareButton={true} url={`${baseUrl}p/${id}`} />
|
<CopyableField content={`${baseUrl}p/${id}`} nativeShareButton={true} url={`${baseUrl}p/${id}`} />
|
||||||
</ShowIf>
|
</ShowIf>
|
||||||
<ShowIf condition={noteFrontmatter.type === ''}>
|
<ShowIf condition={noteFrontmatter.type === NoteType.DOCUMENT}>
|
||||||
<Trans i18nKey={'editor.modal.shareLink.viewOnlyDescription'} />
|
<Trans i18nKey={'editor.modal.shareLink.viewOnlyDescription'} />
|
||||||
<CopyableField content={`${baseUrl}s/${id}`} nativeShareButton={true} url={`${baseUrl}s/${id}`} />
|
<CopyableField content={`${baseUrl}s/${id}`} nativeShareButton={true} url={`${baseUrl}s/${id}`} />
|
||||||
</ShowIf>
|
</ShowIf>
|
||||||
|
|
|
@ -29,7 +29,7 @@ import { useApplicationState } from '../../hooks/common/use-application-state'
|
||||||
import { EditorDocumentRenderer } from './editor-document-renderer/editor-document-renderer'
|
import { EditorDocumentRenderer } from './editor-document-renderer/editor-document-renderer'
|
||||||
import { EditorToRendererCommunicatorContextProvider } from './render-context/editor-to-renderer-communicator-context-provider'
|
import { EditorToRendererCommunicatorContextProvider } from './render-context/editor-to-renderer-communicator-context-provider'
|
||||||
import { Logger } from '../../utils/logger'
|
import { Logger } from '../../utils/logger'
|
||||||
import { NoteType } from '../common/note-frontmatter/types'
|
import { NoteType } from '../../redux/note-details/types/note-details'
|
||||||
|
|
||||||
export interface EditorPagePathParams {
|
export interface EditorPagePathParams {
|
||||||
id: string
|
id: string
|
||||||
|
|
|
@ -8,8 +8,8 @@ import { useSendToRenderer } from '../../../render-page/window-post-message-comm
|
||||||
import { useMemo, useRef } from 'react'
|
import { useMemo, useRef } from 'react'
|
||||||
import { CommunicationMessageType } from '../../../render-page/window-post-message-communicator/rendering-message'
|
import { CommunicationMessageType } from '../../../render-page/window-post-message-communicator/rendering-message'
|
||||||
import { useApplicationState } from '../../../../hooks/common/use-application-state'
|
import { useApplicationState } from '../../../../hooks/common/use-application-state'
|
||||||
import type { RendererFrontmatterInfo } from '../../../common/note-frontmatter/types'
|
|
||||||
import equal from 'fast-deep-equal'
|
import equal from 'fast-deep-equal'
|
||||||
|
import type { RendererFrontmatterInfo } from '../../../../redux/note-details/types/note-details'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the {@link RendererFrontmatterInfo frontmatter data}
|
* Extracts the {@link RendererFrontmatterInfo frontmatter data}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import Reveal from 'reveal.js'
|
import Reveal from 'reveal.js'
|
||||||
import { Logger } from '../../../utils/logger'
|
import { Logger } from '../../../utils/logger'
|
||||||
import type { SlideOptions } from '../../common/note-frontmatter/types'
|
import type { SlideOptions } from '../../../redux/note-details/types/slide-show-options'
|
||||||
|
|
||||||
const log = new Logger('reveal.js')
|
const log = new Logger('reveal.js')
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,11 @@ import { REVEAL_STATUS, useReveal } from './hooks/use-reveal'
|
||||||
import './slideshow.scss'
|
import './slideshow.scss'
|
||||||
import type { ScrollProps } from '../editor-page/synced-scroll/scroll-props'
|
import type { ScrollProps } from '../editor-page/synced-scroll/scroll-props'
|
||||||
import { DocumentLengthLimitReachedAlert } from './document-length-limit-reached-alert'
|
import { DocumentLengthLimitReachedAlert } from './document-length-limit-reached-alert'
|
||||||
import type { SlideOptions } from '../common/note-frontmatter/types'
|
|
||||||
import type { CommonMarkdownRendererProps } from './common-markdown-renderer-props'
|
import type { CommonMarkdownRendererProps } from './common-markdown-renderer-props'
|
||||||
import { LoadingSlide } from './loading-slide'
|
import { LoadingSlide } from './loading-slide'
|
||||||
import { RevealMarkdownExtension } from './markdown-extension/reveal/reveal-markdown-extension'
|
import { RevealMarkdownExtension } from './markdown-extension/reveal/reveal-markdown-extension'
|
||||||
import { useMarkdownExtensions } from './hooks/use-markdown-extensions'
|
import { useMarkdownExtensions } from './hooks/use-markdown-extensions'
|
||||||
|
import type { SlideOptions } from '../../redux/note-details/types/slide-show-options'
|
||||||
|
|
||||||
export interface SlideshowMarkdownRendererProps extends CommonMarkdownRendererProps {
|
export interface SlideshowMarkdownRendererProps extends CommonMarkdownRendererProps {
|
||||||
slideOptions: SlideOptions
|
slideOptions: SlideOptions
|
||||||
|
|
|
@ -13,11 +13,11 @@ import type { ImageClickHandler } from '../markdown-renderer/markdown-extension/
|
||||||
import { useImageClickHandler } from './hooks/use-image-click-handler'
|
import { useImageClickHandler } from './hooks/use-image-click-handler'
|
||||||
import { MarkdownDocument } from './markdown-document'
|
import { MarkdownDocument } from './markdown-document'
|
||||||
import { countWords } from './word-counter'
|
import { countWords } from './word-counter'
|
||||||
import type { RendererFrontmatterInfo } from '../common/note-frontmatter/types'
|
|
||||||
import { useRendererToEditorCommunicator } from '../editor-page/render-context/renderer-to-editor-communicator-context-provider'
|
import { useRendererToEditorCommunicator } from '../editor-page/render-context/renderer-to-editor-communicator-context-provider'
|
||||||
import { useRendererReceiveHandler } from './window-post-message-communicator/hooks/use-renderer-receive-handler'
|
import { useRendererReceiveHandler } from './window-post-message-communicator/hooks/use-renderer-receive-handler'
|
||||||
import { SlideshowMarkdownRenderer } from '../markdown-renderer/slideshow-markdown-renderer'
|
import { SlideshowMarkdownRenderer } from '../markdown-renderer/slideshow-markdown-renderer'
|
||||||
import { initialState } from '../../redux/note-details/initial-state'
|
import { initialState } from '../../redux/note-details/initial-state'
|
||||||
|
import type { RendererFrontmatterInfo } from '../../redux/note-details/types/note-details'
|
||||||
|
|
||||||
export const IframeMarkdownRenderer: React.FC = () => {
|
export const IframeMarkdownRenderer: React.FC = () => {
|
||||||
const [markdownContent, setMarkdownContent] = useState('')
|
const [markdownContent, setMarkdownContent] = useState('')
|
||||||
|
|
|
@ -17,8 +17,8 @@ import './markdown-document.scss'
|
||||||
import { WidthBasedTableOfContents } from './width-based-table-of-contents'
|
import { WidthBasedTableOfContents } from './width-based-table-of-contents'
|
||||||
import { ShowIf } from '../common/show-if/show-if'
|
import { ShowIf } from '../common/show-if/show-if'
|
||||||
import { useApplicationState } from '../../hooks/common/use-application-state'
|
import { useApplicationState } from '../../hooks/common/use-application-state'
|
||||||
import type { RendererFrontmatterInfo } from '../common/note-frontmatter/types'
|
|
||||||
import { InvalidYamlAlert } from '../markdown-renderer/invalid-yaml-alert'
|
import { InvalidYamlAlert } from '../markdown-renderer/invalid-yaml-alert'
|
||||||
|
import type { RendererFrontmatterInfo } from '../../redux/note-details/types/note-details'
|
||||||
|
|
||||||
export interface RendererProps extends ScrollProps {
|
export interface RendererProps extends ScrollProps {
|
||||||
onFirstHeadingChange?: (firstHeading: string | undefined) => void
|
onFirstHeadingChange?: (firstHeading: string | undefined) => void
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import type { ScrollState } from '../../editor-page/synced-scroll/scroll-props'
|
import type { ScrollState } from '../../editor-page/synced-scroll/scroll-props'
|
||||||
import type { RendererFrontmatterInfo } from '../../common/note-frontmatter/types'
|
import type { RendererFrontmatterInfo } from '../../../redux/note-details/types/note-details'
|
||||||
|
|
||||||
export enum CommunicationMessageType {
|
export enum CommunicationMessageType {
|
||||||
SET_MARKDOWN_CONTENT = 'SET_MARKDOWN_CONTENT',
|
SET_MARKDOWN_CONTENT = 'SET_MARKDOWN_CONTENT',
|
||||||
|
|
|
@ -17,7 +17,6 @@ import type { DarkModeConfig } from './dark-mode/types'
|
||||||
import { EditorConfigReducer } from './editor/reducers'
|
import { EditorConfigReducer } from './editor/reducers'
|
||||||
import type { EditorConfig } from './editor/types'
|
import type { EditorConfig } from './editor/types'
|
||||||
import { NoteDetailsReducer } from './note-details/reducer'
|
import { NoteDetailsReducer } from './note-details/reducer'
|
||||||
import type { NoteDetails } from './note-details/types'
|
|
||||||
import { UserReducer } from './user/reducers'
|
import { UserReducer } from './user/reducers'
|
||||||
import type { OptionalUserState } from './user/types'
|
import type { OptionalUserState } from './user/types'
|
||||||
import type { UiNotificationState } from './ui-notifications/types'
|
import type { UiNotificationState } from './ui-notifications/types'
|
||||||
|
@ -27,6 +26,7 @@ import { HistoryReducer } from './history/reducers'
|
||||||
import { RendererStatusReducer } from './renderer-status/reducers'
|
import { RendererStatusReducer } from './renderer-status/reducers'
|
||||||
import type { RendererStatus } from './renderer-status/types'
|
import type { RendererStatus } from './renderer-status/types'
|
||||||
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly'
|
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly'
|
||||||
|
import type { NoteDetails } from './note-details/types/note-details'
|
||||||
|
|
||||||
export interface ApplicationState {
|
export interface ApplicationState {
|
||||||
user: OptionalUserState
|
user: OptionalUserState
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { extractFrontmatter } from './extract-frontmatter'
|
import { extractFrontmatter } from './extractor'
|
||||||
import type { PresentFrontmatterExtractionResult } from './types'
|
import type { PresentFrontmatterExtractionResult } from './types'
|
||||||
|
|
||||||
describe('frontmatter extraction', () => {
|
describe('frontmatter extraction', () => {
|
17
src/redux/note-details/frontmatter-extractor/types.d.ts
vendored
Normal file
17
src/redux/note-details/frontmatter-extractor/types.d.ts
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type FrontmatterExtractionResult = PresentFrontmatterExtractionResult | NonPresentFrontmatterExtractionResult
|
||||||
|
|
||||||
|
export interface PresentFrontmatterExtractionResult {
|
||||||
|
isPresent: true
|
||||||
|
rawText: string
|
||||||
|
lineOffset: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface NonPresentFrontmatterExtractionResult {
|
||||||
|
isPresent: false
|
||||||
|
}
|
|
@ -4,10 +4,10 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { NoteDetails } from './types'
|
|
||||||
import { DateTime } from 'luxon'
|
import { DateTime } from 'luxon'
|
||||||
import type { SlideOptions } from '../../components/common/note-frontmatter/types'
|
import type { NoteDetails } from './types/note-details'
|
||||||
import { NoteTextDirection, NoteType } from '../../components/common/note-frontmatter/types'
|
import type { SlideOptions } from './types/slide-show-options'
|
||||||
|
import { NoteTextDirection, NoteType } from './types/note-details'
|
||||||
|
|
||||||
export const initialSlideOptions: SlideOptions = {
|
export const initialSlideOptions: SlideOptions = {
|
||||||
transition: 'zoom',
|
transition: 'zoom',
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createNoteFrontmatterFromYaml } from './note-frontmatter'
|
import { createNoteFrontmatterFromYaml } from './parser'
|
||||||
|
|
||||||
describe('yaml frontmatter', () => {
|
describe('yaml frontmatter', () => {
|
||||||
it('should parse "title"', () => {
|
it('should parse "title"', () => {
|
|
@ -4,36 +4,30 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// import { RevealOptions } from 'reveal.js'
|
|
||||||
import { load } from 'js-yaml'
|
import { load } from 'js-yaml'
|
||||||
import type { RawNoteFrontmatter, SlideOptions } from './types'
|
import type { SlideOptions } from '../types/slide-show-options'
|
||||||
import { ISO6391, NoteTextDirection, NoteType } from './types'
|
import type { NoteFrontmatter } from '../types/note-details'
|
||||||
import { initialSlideOptions } from '../../../redux/note-details/initial-state'
|
import { NoteTextDirection, NoteType } from '../types/note-details'
|
||||||
|
import { ISO6391 } from '../types/iso6391'
|
||||||
|
import type { RawNoteFrontmatter } from './types'
|
||||||
|
import { initialSlideOptions } from '../initial-state'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that represents the parsed frontmatter metadata of a note.
|
* Creates a new frontmatter metadata instance based on a raw yaml string.
|
||||||
|
* @param rawYaml The frontmatter content in yaml format.
|
||||||
|
* @throws Error when the content string is invalid yaml.
|
||||||
|
* @return Frontmatter metadata instance containing the parsed properties from the yaml content.
|
||||||
*/
|
*/
|
||||||
export interface NoteFrontmatter {
|
export const createNoteFrontmatterFromYaml = (rawYaml: string): NoteFrontmatter => {
|
||||||
title: string
|
const rawNoteFrontmatter = load(rawYaml) as RawNoteFrontmatter
|
||||||
description: string
|
return parseRawNoteFrontmatter(rawNoteFrontmatter)
|
||||||
tags: string[]
|
|
||||||
deprecatedTagsSyntax: boolean
|
|
||||||
robots: string
|
|
||||||
lang: typeof ISO6391[number]
|
|
||||||
dir: NoteTextDirection
|
|
||||||
newlinesAreBreaks: boolean
|
|
||||||
GA: string
|
|
||||||
disqus: string
|
|
||||||
type: NoteType
|
|
||||||
opengraph: Map<string, string>
|
|
||||||
slideOptions: SlideOptions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new frontmatter metadata instance based on the given raw metadata properties.
|
* Creates a new frontmatter metadata instance based on the given raw metadata properties.
|
||||||
* @param rawData A {@link RawNoteFrontmatter} object containing the properties of the parsed yaml frontmatter.
|
* @param rawData A {@link RawNoteFrontmatter} object containing the properties of the parsed yaml frontmatter.
|
||||||
*/
|
*/
|
||||||
export const parseRawNoteFrontmatter = (rawData: RawNoteFrontmatter): NoteFrontmatter => {
|
const parseRawNoteFrontmatter = (rawData: RawNoteFrontmatter): NoteFrontmatter => {
|
||||||
let tags: string[]
|
let tags: string[]
|
||||||
let deprecatedTagsSyntax: boolean
|
let deprecatedTagsSyntax: boolean
|
||||||
if (typeof rawData?.tags === 'string') {
|
if (typeof rawData?.tags === 'string') {
|
||||||
|
@ -55,11 +49,8 @@ export const parseRawNoteFrontmatter = (rawData: RawNoteFrontmatter): NoteFrontm
|
||||||
GA: rawData.GA ?? '',
|
GA: rawData.GA ?? '',
|
||||||
disqus: rawData.disqus ?? '',
|
disqus: rawData.disqus ?? '',
|
||||||
lang: (rawData.lang ? ISO6391.find((lang) => lang === rawData.lang) : undefined) ?? 'en',
|
lang: (rawData.lang ? ISO6391.find((lang) => lang === rawData.lang) : undefined) ?? 'en',
|
||||||
type:
|
type: rawData.type === NoteType.SLIDE ? NoteType.SLIDE : NoteType.DOCUMENT,
|
||||||
(rawData.type ? Object.values(NoteType).find((type) => type === rawData.type) : undefined) ?? NoteType.DOCUMENT,
|
dir: rawData.dir === NoteTextDirection.LTR ? NoteTextDirection.LTR : NoteTextDirection.RTL,
|
||||||
dir:
|
|
||||||
(rawData.dir ? Object.values(NoteTextDirection).find((dir) => dir === rawData.dir) : undefined) ??
|
|
||||||
NoteTextDirection.LTR,
|
|
||||||
opengraph: rawData?.opengraph
|
opengraph: rawData?.opengraph
|
||||||
? new Map<string, string>(Object.entries(rawData.opengraph))
|
? new Map<string, string>(Object.entries(rawData.opengraph))
|
||||||
: new Map<string, string>(),
|
: new Map<string, string>(),
|
||||||
|
@ -110,14 +101,3 @@ const parseNumber = (rawData: unknown | undefined): number | undefined => {
|
||||||
const numValue = Number(rawData)
|
const numValue = Number(rawData)
|
||||||
return isNaN(numValue) ? undefined : numValue
|
return isNaN(numValue) ? undefined : numValue
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new frontmatter metadata instance based on a raw yaml string.
|
|
||||||
* @param rawYaml The frontmatter content in yaml format.
|
|
||||||
* @throws Error when the content string is invalid yaml.
|
|
||||||
* @return Frontmatter metadata instance containing the parsed properties from the yaml content.
|
|
||||||
*/
|
|
||||||
export const createNoteFrontmatterFromYaml = (rawYaml: string): NoteFrontmatter => {
|
|
||||||
const rawNoteFrontmatter = load(rawYaml) as RawNoteFrontmatter
|
|
||||||
return parseRawNoteFrontmatter(rawNoteFrontmatter)
|
|
||||||
}
|
|
20
src/redux/note-details/raw-note-frontmatter-parser/types.d.ts
vendored
Normal file
20
src/redux/note-details/raw-note-frontmatter-parser/types.d.ts
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface RawNoteFrontmatter {
|
||||||
|
title: string | undefined
|
||||||
|
description: string | undefined
|
||||||
|
tags: string | string[] | undefined
|
||||||
|
robots: string | undefined
|
||||||
|
lang: string | undefined
|
||||||
|
dir: string | undefined
|
||||||
|
breaks: boolean | undefined
|
||||||
|
GA: string | undefined
|
||||||
|
disqus: string | undefined
|
||||||
|
type: string | undefined
|
||||||
|
slideOptions: { [key: string]: string } | null
|
||||||
|
opengraph: { [key: string]: string } | null
|
||||||
|
}
|
|
@ -5,15 +5,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Reducer } from 'redux'
|
import type { Reducer } from 'redux'
|
||||||
import type { PresentFrontmatterExtractionResult } from '../../components/common/note-frontmatter/types'
|
import { createNoteFrontmatterFromYaml } from './raw-note-frontmatter-parser/parser'
|
||||||
import type { NoteFrontmatter } from '../../components/common/note-frontmatter/note-frontmatter'
|
import type { NoteDetailsActions } from './types'
|
||||||
import { createNoteFrontmatterFromYaml } from '../../components/common/note-frontmatter/note-frontmatter'
|
|
||||||
import type { NoteDetails, NoteDetailsActions } from './types'
|
|
||||||
import { NoteDetailsActionType } from './types'
|
import { NoteDetailsActionType } from './types'
|
||||||
import { extractFrontmatter } from '../../components/common/note-frontmatter/extract-frontmatter'
|
import { extractFrontmatter } from './frontmatter-extractor/extractor'
|
||||||
import type { NoteDto } from '../../api/notes/types'
|
import type { NoteDto } from '../../api/notes/types'
|
||||||
import { initialState } from './initial-state'
|
import { initialState } from './initial-state'
|
||||||
import { DateTime } from 'luxon'
|
import { DateTime } from 'luxon'
|
||||||
|
import type { NoteDetails, NoteFrontmatter } from './types/note-details'
|
||||||
|
import type { PresentFrontmatterExtractionResult } from './frontmatter-extractor/types'
|
||||||
|
|
||||||
export const NoteDetailsReducer: Reducer<NoteDetails, NoteDetailsActions> = (
|
export const NoteDetailsReducer: Reducer<NoteDetails, NoteDetailsActions> = (
|
||||||
state: NoteDetails = initialState,
|
state: NoteDetails = initialState,
|
||||||
|
@ -75,7 +75,15 @@ const buildStateFromTaskListUpdate = (
|
||||||
*/
|
*/
|
||||||
const buildStateFromMarkdownContentUpdate = (state: NoteDetails, markdownContent: string): NoteDetails => {
|
const buildStateFromMarkdownContentUpdate = (state: NoteDetails, markdownContent: string): NoteDetails => {
|
||||||
const frontmatterExtraction = extractFrontmatter(markdownContent)
|
const frontmatterExtraction = extractFrontmatter(markdownContent)
|
||||||
if (!frontmatterExtraction.isPresent) {
|
if (frontmatterExtraction.isPresent) {
|
||||||
|
return buildStateFromFrontmatterUpdate(
|
||||||
|
{
|
||||||
|
...state,
|
||||||
|
markdownContent: markdownContent
|
||||||
|
},
|
||||||
|
frontmatterExtraction
|
||||||
|
)
|
||||||
|
} else {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
markdownContent: markdownContent,
|
markdownContent: markdownContent,
|
||||||
|
@ -85,13 +93,6 @@ const buildStateFromMarkdownContentUpdate = (state: NoteDetails, markdownContent
|
||||||
frontmatterRendererInfo: initialState.frontmatterRendererInfo
|
frontmatterRendererInfo: initialState.frontmatterRendererInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buildStateFromFrontmatterUpdate(
|
|
||||||
{
|
|
||||||
...state,
|
|
||||||
markdownContent: markdownContent
|
|
||||||
},
|
|
||||||
frontmatterExtraction
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,11 +4,8 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { DateTime } from 'luxon'
|
|
||||||
import type { Action } from 'redux'
|
import type { Action } from 'redux'
|
||||||
import type { NoteFrontmatter } from '../../components/common/note-frontmatter/note-frontmatter'
|
|
||||||
import type { NoteDto } from '../../api/notes/types'
|
import type { NoteDto } from '../../api/notes/types'
|
||||||
import type { RendererFrontmatterInfo } from '../../components/common/note-frontmatter/types'
|
|
||||||
|
|
||||||
export enum NoteDetailsActionType {
|
export enum NoteDetailsActionType {
|
||||||
SET_DOCUMENT_CONTENT = 'note-details/content/set',
|
SET_DOCUMENT_CONTENT = 'note-details/content/set',
|
||||||
|
@ -16,28 +13,6 @@ export enum NoteDetailsActionType {
|
||||||
UPDATE_NOTE_TITLE_BY_FIRST_HEADING = 'note-details/update-note-title-by-first-heading',
|
UPDATE_NOTE_TITLE_BY_FIRST_HEADING = 'note-details/update-note-title-by-first-heading',
|
||||||
UPDATE_TASK_LIST_CHECKBOX = 'note-details/update-task-list-checkbox'
|
UPDATE_TASK_LIST_CHECKBOX = 'note-details/update-task-list-checkbox'
|
||||||
}
|
}
|
||||||
interface LastChange {
|
|
||||||
userName: string
|
|
||||||
timestamp: DateTime
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redux state containing the currently loaded note with its content and metadata.
|
|
||||||
*/
|
|
||||||
export interface NoteDetails {
|
|
||||||
markdownContent: string
|
|
||||||
rawFrontmatter: string
|
|
||||||
frontmatter: NoteFrontmatter
|
|
||||||
frontmatterRendererInfo: RendererFrontmatterInfo
|
|
||||||
id: string
|
|
||||||
createTime: DateTime
|
|
||||||
lastChange: LastChange
|
|
||||||
viewCount: number
|
|
||||||
alias: string
|
|
||||||
authorship: string[]
|
|
||||||
noteTitle: string
|
|
||||||
firstHeading?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type NoteDetailsActions =
|
export type NoteDetailsActions =
|
||||||
| SetNoteDocumentContentAction
|
| SetNoteDocumentContentAction
|
||||||
|
|
|
@ -4,50 +4,6 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { RevealOptions } from 'reveal.js'
|
|
||||||
|
|
||||||
export type FrontmatterExtractionResult = PresentFrontmatterExtractionResult | NonPresentFrontmatterExtractionResult
|
|
||||||
|
|
||||||
export type WantedRevealOptions =
|
|
||||||
| 'autoSlide'
|
|
||||||
| 'autoSlideStoppable'
|
|
||||||
| 'transition'
|
|
||||||
| 'backgroundTransition'
|
|
||||||
| 'slideNumber'
|
|
||||||
export type SlideOptions = Required<Pick<RevealOptions, WantedRevealOptions>>
|
|
||||||
|
|
||||||
export interface RendererFrontmatterInfo {
|
|
||||||
lineOffset: number
|
|
||||||
frontmatterInvalid: boolean
|
|
||||||
deprecatedSyntax: boolean
|
|
||||||
slideOptions: SlideOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PresentFrontmatterExtractionResult {
|
|
||||||
isPresent: true
|
|
||||||
rawText: string
|
|
||||||
lineOffset: number
|
|
||||||
}
|
|
||||||
|
|
||||||
interface NonPresentFrontmatterExtractionResult {
|
|
||||||
isPresent: false
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RawNoteFrontmatter {
|
|
||||||
title: string | undefined
|
|
||||||
description: string | undefined
|
|
||||||
tags: string | string[] | undefined
|
|
||||||
robots: string | undefined
|
|
||||||
lang: string | undefined
|
|
||||||
dir: string | undefined
|
|
||||||
breaks: boolean | undefined
|
|
||||||
GA: string | undefined
|
|
||||||
disqus: string | undefined
|
|
||||||
type: string | undefined
|
|
||||||
slideOptions: { [key: string]: string } | null
|
|
||||||
opengraph: { [key: string]: string } | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ISO6391 = [
|
export const ISO6391 = [
|
||||||
'aa',
|
'aa',
|
||||||
'ab',
|
'ab',
|
||||||
|
@ -252,13 +208,3 @@ export const ISO6391 = [
|
||||||
'zh-tw',
|
'zh-tw',
|
||||||
'zu'
|
'zu'
|
||||||
] as const
|
] as const
|
||||||
|
|
||||||
export enum NoteType {
|
|
||||||
DOCUMENT = '',
|
|
||||||
SLIDE = 'slide'
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum NoteTextDirection {
|
|
||||||
LTR = 'ltr',
|
|
||||||
RTL = 'rtl'
|
|
||||||
}
|
|
63
src/redux/note-details/types/note-details.ts
Normal file
63
src/redux/note-details/types/note-details.ts
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { DateTime } from 'luxon'
|
||||||
|
import type { SlideOptions } from './slide-show-options'
|
||||||
|
import type { ISO6391 } from './iso6391'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redux state containing the currently loaded note with its content and metadata.
|
||||||
|
*/
|
||||||
|
export interface NoteDetails {
|
||||||
|
markdownContent: string
|
||||||
|
rawFrontmatter: string
|
||||||
|
frontmatter: NoteFrontmatter
|
||||||
|
frontmatterRendererInfo: RendererFrontmatterInfo
|
||||||
|
id: string
|
||||||
|
createTime: DateTime
|
||||||
|
lastChange: {
|
||||||
|
userName: string
|
||||||
|
timestamp: DateTime
|
||||||
|
}
|
||||||
|
viewCount: number
|
||||||
|
alias: string
|
||||||
|
authorship: string[]
|
||||||
|
noteTitle: string
|
||||||
|
firstHeading?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NoteFrontmatter {
|
||||||
|
title: string
|
||||||
|
description: string
|
||||||
|
tags: string[]
|
||||||
|
deprecatedTagsSyntax: boolean
|
||||||
|
robots: string
|
||||||
|
lang: typeof ISO6391[number]
|
||||||
|
dir: NoteTextDirection
|
||||||
|
newlinesAreBreaks: boolean
|
||||||
|
GA: string
|
||||||
|
disqus: string
|
||||||
|
type: NoteType
|
||||||
|
opengraph: Map<string, string>
|
||||||
|
slideOptions: SlideOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum NoteTextDirection {
|
||||||
|
LTR = 'ltr',
|
||||||
|
RTL = 'rtl'
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum NoteType {
|
||||||
|
DOCUMENT = '',
|
||||||
|
SLIDE = 'slide'
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RendererFrontmatterInfo {
|
||||||
|
lineOffset: number
|
||||||
|
frontmatterInvalid: boolean
|
||||||
|
deprecatedSyntax: boolean
|
||||||
|
slideOptions: SlideOptions
|
||||||
|
}
|
11
src/redux/note-details/types/slide-show-options.d.ts
vendored
Normal file
11
src/redux/note-details/types/slide-show-options.d.ts
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { RevealOptions } from 'reveal.js'
|
||||||
|
|
||||||
|
type WantedRevealOptions = 'autoSlide' | 'autoSlideStoppable' | 'transition' | 'backgroundTransition' | 'slideNumber'
|
||||||
|
|
||||||
|
export type SlideOptions = Required<Pick<RevealOptions, WantedRevealOptions>>
|
Loading…
Add table
Add a link
Reference in a new issue