mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(client) view: show markdown without shift
This commit is contained in:
parent
301bfa3234
commit
635b195d48
7 changed files with 128 additions and 58 deletions
|
|
@ -80,7 +80,7 @@ module.exports = {
|
|||
[modules + '/edit-names']: `${dirModules}/edit-names.js`,
|
||||
[modules + '/edit-names-vim']: `${dirModules}/edit-names-vim.js`,
|
||||
[modules + '/menu']: `${dirModules}/menu.js`,
|
||||
[modules + '/view']: `${dirModules}/view.js`,
|
||||
[modules + '/view']: `${dirModules}/view/index.js`,
|
||||
[modules + '/help']: `${dirModules}/help.js`,
|
||||
[modules + '/markdown']: `${dirModules}/markdown.js`,
|
||||
[modules + '/config']: `${dirModules}/config/index.js`,
|
||||
|
|
|
|||
1
HELP.md
1
HELP.md
|
|
@ -156,7 +156,6 @@ Then, start the server again with `cloudcmd` and reload the page.
|
|||
| `F1` | help
|
||||
| `F2` | show `user menu`
|
||||
| `F3` | view, change directory
|
||||
| `Shift + F3` | view as markdown
|
||||
| `F4` | edit
|
||||
| `Shift + F4` | edit in "vim" mode
|
||||
| `F5` | copy
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ const toggleVim = (keyCode) => {
|
|||
if (keyCode === KEY.ESC) {
|
||||
_config('vim', !config('vim'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Chars([]);
|
||||
|
||||
|
|
|
|||
54
client/modules/view/get-type.js
Normal file
54
client/modules/view/get-type.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
'use strict';
|
||||
|
||||
const currify = require('currify');
|
||||
const testRegExp = currify((name, reg) => reg.test(name));
|
||||
const getRegExp = (ext) => RegExp(`\\.${ext}$`, 'i');
|
||||
|
||||
const isPDF = (a) => /\.pdf$/i.test(a);
|
||||
const isHTML = (a) => /\.html$/.test(a);
|
||||
const isMarkdown = (a) => /.\.md$/.test(a);
|
||||
|
||||
module.exports = (name) => {
|
||||
if (isPDF(name))
|
||||
return 'pdf';
|
||||
|
||||
if (isImage(name))
|
||||
return 'image';
|
||||
|
||||
if (isMedia(name))
|
||||
return 'media';
|
||||
|
||||
if (isHTML(name))
|
||||
return 'html';
|
||||
|
||||
if (isMarkdown(name))
|
||||
return 'markdown';
|
||||
};
|
||||
|
||||
function isImage(name) {
|
||||
const images = [
|
||||
'jp(e|g|eg)',
|
||||
'gif',
|
||||
'png',
|
||||
'bmp',
|
||||
'webp',
|
||||
'svg',
|
||||
'ico',
|
||||
];
|
||||
|
||||
return images
|
||||
.map(getRegExp)
|
||||
.some(testRegExp(name));
|
||||
}
|
||||
|
||||
function isMedia(name) {
|
||||
return isAudio(name) || isVideo(name);
|
||||
}
|
||||
|
||||
function isAudio(name) {
|
||||
return /\.(mp3|ogg|m4a)$/i.test(name);
|
||||
}
|
||||
|
||||
function isVideo(name) {
|
||||
return /\.(mp4|avi|webm)$/i.test(name);
|
||||
}
|
||||
|
|
@ -2,30 +2,34 @@
|
|||
|
||||
/* global CloudCmd, DOM */
|
||||
|
||||
require('../../css/view.css');
|
||||
require('../../../css/view.css');
|
||||
|
||||
const rendy = require('rendy');
|
||||
const currify = require('currify');
|
||||
const wraptile = require('wraptile');
|
||||
const tryToCatch = require('try-to-catch');
|
||||
const load = require('load.js');
|
||||
|
||||
const modal = require('@cloudcmd/modal');
|
||||
const createElement = require('@cloudcmd/create-element');
|
||||
|
||||
const {time} = require('../../common/util');
|
||||
const {FS} = require('../../common/cloudfunc');
|
||||
const {time} = require('../../../common/util');
|
||||
const {FS} = require('../../../common/cloudfunc');
|
||||
const {
|
||||
isImage,
|
||||
isAudio,
|
||||
getType,
|
||||
} = require('./types');
|
||||
|
||||
const Files = require('../dom/files');
|
||||
const Events = require('../dom/events');
|
||||
const load = require('load.js');
|
||||
const Images = require('../dom/images');
|
||||
const Files = require('../../dom/files');
|
||||
const Events = require('../../dom/events');
|
||||
const Images = require('../../dom/images');
|
||||
|
||||
const {encode} = require('../../common/entity');
|
||||
const {encode} = require('../../../common/entity');
|
||||
|
||||
const {assign} = Object;
|
||||
const {isArray} = Array;
|
||||
|
||||
const testRegExp = currify((name, reg) => reg.test(name));
|
||||
const lifo = currify((fn, el, cb, name) => fn(name, el, cb));
|
||||
const series = wraptile((...a) => {
|
||||
for (const f of a)
|
||||
|
|
@ -36,7 +40,6 @@ const isFn = (a) => typeof a === 'function';
|
|||
|
||||
const noop = () => {};
|
||||
const addEvent = lifo(Events.add);
|
||||
const getRegExp = (ext) => RegExp(`\\.${ext}$`, 'i');
|
||||
|
||||
const loadCSS = load.css;
|
||||
|
||||
|
|
@ -127,6 +130,9 @@ async function show(data, options) {
|
|||
default:
|
||||
return viewFile();
|
||||
|
||||
case 'markdown':
|
||||
return await CloudCmd.Markdown.show(Info.path);
|
||||
|
||||
case 'html':
|
||||
return viewHtml(path);
|
||||
|
||||
|
|
@ -271,51 +277,6 @@ function viewImage(prefixURL) {
|
|||
modal.open(titles, config);
|
||||
}
|
||||
|
||||
function isImage(name) {
|
||||
const images = [
|
||||
'jp(e|g|eg)',
|
||||
'gif',
|
||||
'png',
|
||||
'bmp',
|
||||
'webp',
|
||||
'svg',
|
||||
'ico',
|
||||
];
|
||||
|
||||
return images
|
||||
.map(getRegExp)
|
||||
.some(testRegExp(name));
|
||||
}
|
||||
|
||||
function isMedia(name) {
|
||||
return isAudio(name) || isVideo(name);
|
||||
}
|
||||
|
||||
function isAudio(name) {
|
||||
return /\.(mp3|ogg|m4a)$/i.test(name);
|
||||
}
|
||||
|
||||
function isVideo(name) {
|
||||
return /\.(mp4|avi|webm)$/i.test(name);
|
||||
}
|
||||
|
||||
const isPDF = (name) => /\.pdf$/i.test(name);
|
||||
const isHTML = (name) => /\.html/.test(name);
|
||||
|
||||
function getType(name) {
|
||||
if (isPDF(name))
|
||||
return 'pdf';
|
||||
|
||||
if (isImage(name))
|
||||
return 'image';
|
||||
|
||||
if (isMedia(name))
|
||||
return 'media';
|
||||
|
||||
if (isHTML(name))
|
||||
return 'html';
|
||||
}
|
||||
|
||||
async function getMediaElement(src) {
|
||||
check(src);
|
||||
|
||||
56
client/modules/view/types.js
Normal file
56
client/modules/view/types.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
'use strict';
|
||||
|
||||
const currify = require('currify');
|
||||
const testRegExp = currify((name, reg) => reg.test(name));
|
||||
const getRegExp = (ext) => RegExp(`\\.${ext}$`, 'i');
|
||||
|
||||
const isPDF = (a) => /\.pdf$/i.test(a);
|
||||
const isHTML = (a) => /\.html$/.test(a);
|
||||
const isMarkdown = (a) => /.\.md$/.test(a);
|
||||
|
||||
module.exports.getType = (name) => {
|
||||
if (isPDF(name))
|
||||
return 'pdf';
|
||||
|
||||
if (isImage(name))
|
||||
return 'image';
|
||||
|
||||
if (isMedia(name))
|
||||
return 'media';
|
||||
|
||||
if (isHTML(name))
|
||||
return 'html';
|
||||
|
||||
if (isMarkdown(name))
|
||||
return 'markdown';
|
||||
};
|
||||
|
||||
module.exports.isImage = isImage;
|
||||
function isImage(name) {
|
||||
const images = [
|
||||
'jp(e|g|eg)',
|
||||
'gif',
|
||||
'png',
|
||||
'bmp',
|
||||
'webp',
|
||||
'svg',
|
||||
'ico',
|
||||
];
|
||||
|
||||
return images
|
||||
.map(getRegExp)
|
||||
.some(testRegExp(name));
|
||||
}
|
||||
|
||||
function isMedia(name) {
|
||||
return isAudio(name) || isVideo(name);
|
||||
}
|
||||
|
||||
module.exports.isAudiot = isAudio;
|
||||
function isAudio(name) {
|
||||
return /\.(mp3|ogg|m4a)$/i.test(name);
|
||||
}
|
||||
|
||||
function isVideo(name) {
|
||||
return /\.(mp4|avi|webm)$/i.test(name);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue