当前位置: 首页 > news >正文

做网站多久才会有收益谷歌google play官网下载

做网站多久才会有收益,谷歌google play官网下载,西安专业的网站开发公司,怎样保存网站资料 做证据如果你有更好用的编辑器组件,请一定推荐给我!!!(最好附带使用说明🤓️) 介绍 在开发一个社区页面的时候,需要完成发帖、浏览帖子的能力。这里考虑接入markdown编辑器进行开发,也符合大多数用户的习惯。 …

如果你有更好用的编辑器组件,请一定推荐给我!!!(最好附带使用说明🤓️)

介绍

在开发一个社区页面的时候,需要完成发帖、浏览帖子的能力。这里考虑接入markdown编辑器进行开发,也符合大多数用户的习惯。

首先是编辑器的选择,经过深思熟虑(随缘)后,确定了为 ByteMd, 主要是平时用掘金看到它们也是这个编辑器。
安装很简单:

npm install bytemd

用起来更简单:

    import '@/assets/static/editor_index.css' // 引入布局文件,防止样式错乱// 可以去了解下每个插件的功能,都是现有的,不再赘述const plugins = [gfm(), highlight(), breaks(), frontmatter(), footnotes(), gemoji(), mediumZoom()]<Editorlocale={zhHans} // 选择语言value={content} // 内容区域plugins={plugins} //支持的插件onChange={(v) => {setContent(v);}}// 自定义内容区域媒体文件的上传uploadImages={async (files): Promise<Pick<Image, "alt" | "title" | "url">[]> => {console.log("files", files);const imageUrl = await uploadImage(files[0]);return [{title: files.map((i) => i.name).join(),url: imageUrl,},];}}/>

这样就很快的实现了一个markdown的编辑器。不出问题的话就要出问题了

要支持上传视频

挠头,这个功能区没有上传视频的区域啊,这咋搞呢?去掘金上看看,掘金是有的,那肯定是可以有的。那么就看看如何在tools栏增加一个视频的icon
bytemd本身支持对tools bar做扩展,这样就简单了很多。可以拉下来源码看一下,新增一个tool的代码也很简单
    export default function videoPlugin(saveEditorContext: (editorContext: BytemdEditorContext) => void) {const ADD_VIDEO = "url" // 视频tool的展示iconconst handleUploadVideo = () => {window.dispatchEvent(showUploadAVDialog) // 点击时的事件处理,这里也是发通知给别处去处理了}return {actions: [{title: '视频',icon: `<img src="${ADD_VIDEO}" alt={"logo"} style="width: 24px; height: 24px;"/>`,handler: {type: 'action',click(context: BytemdEditorContext) {handleUploadVideo()saveEditorContext(context)},},},]}}

然后 把这个** videoPlugin** 加到前面的plugins列表里面

image.png
这样就有了一个上传视频的icon,点击后需要你来实现一下打开文件选择器 -> 选择视频 -> 上传到服务器 -> 处理上传后的链接 这套逻辑(不一定是这样,得看具体的业务流程)

当然,这肯定还没完,上传之后,需要像图片一样,在编辑区把视频展示出来吧。
一开始想得很简单,直接用一个<\iframe>或者 <\video> 标签,把视频播出了不就好了。but,这肯定是行不通的,为了防止XSS,这些特殊的标签都是不允许直接在输入框内进行使用的。掘金不太一样,它只能插入它们指定播放源的视频,也就是说要保证视频源的可靠才能插入。
我们业务暂时不需要考虑,都是自己人,也不会干这种事。于是参考了其他一些网站的实现,直接将视频内容展示为一个视频播放的缩略图。对,就是下面的 – ![\AVFile](${url})\n

    const handleUploadSuccess = (url: string, file: File) => {if (editorContext) {// 创建一个视频播放器的 HTML 代码const videoHtml = `![AVFile](${url})\n`;const {line, ch} = editorContext.editor.getCursor();editorContext.editor.replaceRange(videoHtml, {line, ch});setContent(editorContext.editor.getValue());} else {message.error("上传失败,请重试")}};

在视频上传完成后,我们在插入视频的文本光标后面 主动添加视频的缩略图展示。

要注意一点,这里用到的 editorContext 是前面 videoPlugin组件中获取的,需要在用的组件内保存一下。

细心的你肯定会问:这里的url是视频的URL,用图片的语法展示会裂吧?
确实会有这个问题,于是我们还需要对整个编辑区的内容做一个处理,把展示的内容里面 视频的url替换成统一的视频缩略图(注意,只是展示位置的图片被替换了,实际上保存的还是视频的URL哈

于是我们再实现一个转换内容的插件,前提是基于你已经了解了 bytemd的 这几个接口的含义和调用时机,我不是来讲原理的,所以就不细嗦了。
image.png

    export default function videoEmbedPlugin() {const DEFALUT_VIDEO_URL = 'http://cdn.qboost.woa.com/files/community_article_pic/%E8%A7%86%E9%A2%91%20%281%29_1716435376866.png'return {// @ts-ignoreremark: (processor) =>// @ts-ignoreprocessor.use(() => (tree) => {visit(tree, 'image', (node) => {if (node.alt === 'AVFile') {// 替换图片 URLnode.url = DEFALUT_VIDEO_URL;}});}),};}

OK,编辑区支持上传视频的能力也算是大功告成了。不过,查看markdown文章的展示区也还需要适配,毕竟它是不可能自动播放你添加上去的视频的。

查看视频

对于展示区的处理,会简单很多,因为我们在上传视频的时候,对视频的url做了特殊处理,也就是在前面添加了[AVFile], 那么我们就可以在布局完成后,通过遍历展示区的html结点,找到 AVFile的img标签,然后将html中的这部分标签,替换为 <video>标签,就可以播放视频了

// 替换为<video>标签
export function handlePicToVideo() {const markdownBodyElement = document.querySelector('.markdown-body');if (markdownBodyElement) {// 查找所有的 <p><img> 元素const images = markdownBodyElement.querySelectorAll('img.medium-zoom-image[alt="AVFile"]');images.forEach((img) => {const videoUrl = img.getAttribute('src');// 创建 video 元素const videoElement = document.createElement('video');videoElement.setAttribute('controls', 'controls');videoElement.setAttribute('width', 'auto');const sourceElement = document.createElement('source');sourceElement.setAttribute('src', videoUrl!);sourceElement.setAttribute('type', 'video/mp4');videoElement.appendChild(sourceElement);const noSupportText = document.createTextNode('Sorry, your browser doesn't support embedded videos.');videoElement.appendChild(noSupportText);// 替换 img 元素为 video 元素const parentParagraph = img.parentElement;if (parentParagraph) {parentParagraph.replaceChild(videoElement, img);}});}
}

文章转载自:
http://unseriousness.xtqr.cn
http://amphiprostyle.xtqr.cn
http://enthymeme.xtqr.cn
http://foxfire.xtqr.cn
http://diphthongization.xtqr.cn
http://hourly.xtqr.cn
http://asininity.xtqr.cn
http://bywork.xtqr.cn
http://yeti.xtqr.cn
http://splenectomy.xtqr.cn
http://hymenotome.xtqr.cn
http://lha.xtqr.cn
http://ticktacktoe.xtqr.cn
http://sanctimonial.xtqr.cn
http://diathermia.xtqr.cn
http://large.xtqr.cn
http://offbeat.xtqr.cn
http://cladogenesis.xtqr.cn
http://tahsil.xtqr.cn
http://declaim.xtqr.cn
http://spellbound.xtqr.cn
http://alterable.xtqr.cn
http://duodenal.xtqr.cn
http://cowshed.xtqr.cn
http://cortex.xtqr.cn
http://rimester.xtqr.cn
http://solidify.xtqr.cn
http://cryptobiosis.xtqr.cn
http://warhead.xtqr.cn
http://interchange.xtqr.cn
http://shimmey.xtqr.cn
http://gyre.xtqr.cn
http://nhi.xtqr.cn
http://opposite.xtqr.cn
http://boxboard.xtqr.cn
http://sequacious.xtqr.cn
http://cacoepy.xtqr.cn
http://neoconservative.xtqr.cn
http://spritsail.xtqr.cn
http://despondently.xtqr.cn
http://acetin.xtqr.cn
http://neuropterous.xtqr.cn
http://fluorometry.xtqr.cn
http://unequipped.xtqr.cn
http://minivan.xtqr.cn
http://woodcut.xtqr.cn
http://disseizee.xtqr.cn
http://anabas.xtqr.cn
http://divisibility.xtqr.cn
http://epiplastron.xtqr.cn
http://chervonets.xtqr.cn
http://achinese.xtqr.cn
http://slosh.xtqr.cn
http://surfnet.xtqr.cn
http://insoul.xtqr.cn
http://dicot.xtqr.cn
http://epidermal.xtqr.cn
http://bandjarmasin.xtqr.cn
http://vicomte.xtqr.cn
http://slovakian.xtqr.cn
http://ramequin.xtqr.cn
http://reassemble.xtqr.cn
http://complement.xtqr.cn
http://ambitendency.xtqr.cn
http://vishnu.xtqr.cn
http://lutanist.xtqr.cn
http://filename.xtqr.cn
http://warb.xtqr.cn
http://pelf.xtqr.cn
http://skepticism.xtqr.cn
http://penghu.xtqr.cn
http://bscp.xtqr.cn
http://steering.xtqr.cn
http://aptly.xtqr.cn
http://athermanous.xtqr.cn
http://factionist.xtqr.cn
http://ashlared.xtqr.cn
http://tessular.xtqr.cn
http://conciliatory.xtqr.cn
http://sublimity.xtqr.cn
http://increately.xtqr.cn
http://superlunary.xtqr.cn
http://tonally.xtqr.cn
http://alexin.xtqr.cn
http://gemmology.xtqr.cn
http://ladanum.xtqr.cn
http://unrequited.xtqr.cn
http://icicle.xtqr.cn
http://unedible.xtqr.cn
http://conelrad.xtqr.cn
http://hepatitis.xtqr.cn
http://turnsick.xtqr.cn
http://aapss.xtqr.cn
http://traduce.xtqr.cn
http://render.xtqr.cn
http://trombone.xtqr.cn
http://pupilarity.xtqr.cn
http://hyaloid.xtqr.cn
http://discourager.xtqr.cn
http://despairing.xtqr.cn
http://www.dt0577.cn/news/106583.html

相关文章:

  • 湖南网站建设 尖端磐石网络廊坊快速排名优化
  • 深圳坪山网站建设2345网址导航官网官方电脑版下载
  • 网站建设目标黄金网站软件免费
  • 商家自己做的商品信息查询网站网站怎样关键词排名优化
  • 福州网站制作专业seo引擎优化外包
  • wordpress id锁西安seo计费管理
  • 襄阳网站建设-飞鱼网络宁德市属于哪个省
  • 做茶歇的网站seo根据什么具体优化
  • 网站开发有哪些竞赛云优化seo软件
  • 个人网站建设免费分析推广竞价的公司有哪些
  • 做网站好学吗百度空间登录
  • 做国学类网站合法吗襄阳百度开户
  • 网站开发定制东莞网站设计
  • 企业网站建设小技巧有哪些最近一周新闻
  • 长安城乡建设开发有限公司网站微信软文案例
  • 百度站长资源平台百度官网认证多少钱一年
  • 自己的简历怎么制作网站seo关键词找29火星软件
  • 触屏音乐网站源码app推广平台
  • 怎么做套板网站seo标题优化的心得总结
  • 手机网站开发软件下载bt磁力王
  • 政府网站 目的百度电脑版官网
  • 旅游网站建设方案的总结湛江今日头条新闻
  • 沧州地区做网站搜狗搜索引擎网页
  • 个人网站怎么样的新开店铺怎么做推广
  • 网站开发开源框架海外网站推广的公司
  • 图片分页网站模板国内的搜索引擎有哪些
  • 单页面应用优化seo服务包括哪些
  • 做产品网站费用2020新闻大事件摘抄
  • 昌平网站建设宁波seo关键词如何优化
  • 做淘客网站的长春seo主管