mirror of
https://github.com/purocean/yn.git
synced 2026-08-30 17:47:18 +08:00
feat: add support for creating files with custom extensions
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
@click="emits('updateDocType', item)"
|
||||
>
|
||||
<input type="radio" :checked="item.id === docType?.id" />
|
||||
{{ item.displayName }}({{ item.extension[0] }})
|
||||
<span>{{ item.displayName }}</span>
|
||||
<span v-if="item.extension.join(',')">({{ item.extension.join(',') }})</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
@@ -48,7 +49,8 @@ const xCategories = computed(() => props.categories.map(x => ({
|
||||
.create-file-panel {
|
||||
.category-list-wrapper {
|
||||
max-height: calc(100vh - 300px);
|
||||
overflow-y: auto
|
||||
overflow-y: auto;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.category {
|
||||
|
||||
@@ -182,11 +182,25 @@ export async function createDoc (doc: Optional<Pick<Doc, 'repo' | 'path' | 'cont
|
||||
export async function createDoc (doc: Optional<Pick<Doc, 'repo' | 'path' | 'content'>, 'path'>, baseDoc?: Doc) {
|
||||
const docType = shallowRef<DocType | null | undefined>(null)
|
||||
|
||||
const othersDocCategoryName = '__others__'
|
||||
|
||||
if (!doc.path) {
|
||||
if (baseDoc) {
|
||||
const currentPath = baseDoc.type === 'dir' ? baseDoc.path : dirname(baseDoc.path)
|
||||
|
||||
const categories = getAllDocCategories()
|
||||
const categories = getAllDocCategories().concat({
|
||||
category: othersDocCategoryName,
|
||||
displayName: t('others'),
|
||||
types: [
|
||||
{
|
||||
id: 'custom',
|
||||
displayName: t('document.custom-extension'),
|
||||
extension: [''],
|
||||
plain: true,
|
||||
buildNewContent: () => ''
|
||||
}
|
||||
]
|
||||
})
|
||||
const markdownCategory = categories.find(x => x.category === 'markdown')
|
||||
const mdType = markdownCategory?.types.find(x => x.extension.includes(misc.MARKDOWN_FILE_EXT))
|
||||
docType.value = mdType
|
||||
@@ -217,11 +231,12 @@ export async function createDoc (doc: Optional<Pick<Doc, 'repo' | 'path' | 'cont
|
||||
throw new Error('Need doc type')
|
||||
}
|
||||
|
||||
const ext = docType.value.extension[0] || ''
|
||||
const supportedExts = docType.value.extension
|
||||
|
||||
filename = filename.replace(/\/$/, '')
|
||||
if (!filename.endsWith(ext)) {
|
||||
filename += ext
|
||||
const ext = extname(filename)
|
||||
if (!supportedExts.includes(ext)) {
|
||||
filename += (docType.value.extension[0] || '')
|
||||
}
|
||||
|
||||
doc.path = join(currentPath, normalizeSep(filename))
|
||||
@@ -282,7 +297,7 @@ export async function createDoc (doc: Optional<Pick<Doc, 'repo' | 'path' | 'cont
|
||||
|
||||
checkFilePath(file.path)
|
||||
|
||||
if (!content) {
|
||||
if (typeof content !== 'string') {
|
||||
throw new Error('Could not get content')
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ const data = {
|
||||
'demo-tips': 'Some features are not available in DEMO mode.',
|
||||
'more': 'More',
|
||||
'copied': 'Copied',
|
||||
'others': 'Others',
|
||||
'insert-different-repo-doc': 'Documents from different repository cannot be inserted',
|
||||
'need-clipboard-permission': 'Please grant clipboard permissions',
|
||||
'click-to-copy': 'Click to copy',
|
||||
@@ -191,6 +192,7 @@ const data = {
|
||||
'password-open': '[Open] Please enter password of the file',
|
||||
'wrong-password': 'Wrong Password',
|
||||
'file-transform-error': 'Encrypted and unencrypted files cannot be converted to each other',
|
||||
'custom-extension': 'Custom Extension',
|
||||
'create-dialog': {
|
||||
'title': 'Create a file',
|
||||
'hint': 'File name',
|
||||
|
||||
@@ -12,6 +12,7 @@ const data: BaseLanguage = {
|
||||
'demo-tips': 'DEMO 模式下一些功能不可用',
|
||||
'more': '更多',
|
||||
'copied': '已复制',
|
||||
'others': '其他',
|
||||
'insert-different-repo-doc': '不能插入不同仓库的文档',
|
||||
'need-clipboard-permission': '请授予剪切板权限',
|
||||
'click-to-copy': '单击复制',
|
||||
@@ -192,6 +193,7 @@ const data: BaseLanguage = {
|
||||
'password-open': '[打开] 请输入密码',
|
||||
'wrong-password': '密码错误',
|
||||
'file-transform-error': '加密文件和非加密文件不能互相转换',
|
||||
'custom-extension': '自定义扩展名',
|
||||
'create-dialog': {
|
||||
'title': '创建文件',
|
||||
'hint': '文件名',
|
||||
|
||||
@@ -12,6 +12,7 @@ const data: BaseLanguage = {
|
||||
'demo-tips': 'DEMO 模式下某些功能不可用',
|
||||
'more': '更多',
|
||||
'copied': '已複製',
|
||||
'others': '其他',
|
||||
'insert-different-repo-doc': '不能插入不同倉庫的文檔',
|
||||
'need-clipboard-permission': '請授予剪貼簿權限',
|
||||
'click-to-copy': '點擊複製',
|
||||
@@ -192,6 +193,7 @@ const data: BaseLanguage = {
|
||||
'password-open': '[打開] 請輸入密碼',
|
||||
'wrong-password': '密碼錯誤',
|
||||
'file-transform-error': '加密文件和非加密文件不能互相轉換',
|
||||
'custom-extension': '自訂擴展名',
|
||||
'create-dialog': {
|
||||
'title': '創建文件',
|
||||
'hint': '文件名',
|
||||
|
||||
Reference in New Issue
Block a user