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

做网站好做吗seo优化方法

做网站好做吗,seo优化方法,wordpress前端集成短信功能,游戏开发课程向 DeepSeek R1 提问: 我想写一个Web 前端网页,后台用 nodejs js-mdict , 实现在线查询英语单词,并能显示图片 1. 项目结构 首先,创建一个项目目录,结构如下: mydict-app/ ├── public/ │ ├── …

向 DeepSeek R1 提问:
我想写一个Web 前端网页,后台用 nodejs + js-mdict , 实现在线查询英语单词,并能显示图片

1. 项目结构

首先,创建一个项目目录,结构如下:

mydict-app/
├── public/
│   ├── index.html
│   ├── styles.css
│   └── script.js
├── server/
│   └── server.js
├── package.json
└── README.md

英汉词典文件(*.mdx , *.mdd)  已经放在 /js/testdict/ 

2. 安装依赖

在项目根目录下运行以下命令,初始化项目并安装所需的依赖:
cd mydict-app
npm init -y
npm install express
added 69 packages in 6s

npm install js-mdict
added 3 packages in 2s

3. 创建前端页面

在 public/index.html 中创建一个简单的HTML页面,包含一个输入框和三个按钮用于查询单词:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="ie=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>查询英汉词典</title><script src="jquery.js"></script><style>
/* portrait 判断为竖屏 */
@media only screen and (orientation: portrait){#lab1 {display:none;}
} 
/* landscape 判断为横屏 */ 
@media only screen and (orientation: landscape){#lab1 {display: ;}
}    </style>
</head>
<body><form name="form" id="form" action="search" method="GET" target="iframe"><label id="lab1">请输入:</label><input type="text" name="word" id="word" size="30" placeholder="请输入英文单词"><input type="submit" name="eng_han" value="英译汉"><input type="button" name="btn1" id="btn1" value="前缀查询"><input type="button" name="btn2" id="btn2" value="模糊查询"></form><p></p>
<div style="float:left; width:100%;"><div id="result" style="float:left; width:75%; height:500; border:2px;"><iframe name="iframe" id="iframe" width="100%" height="500"> </iframe></div><div id="alist" style="float:right; width:25%; height:500; border:2px;"></div>
</div><script src="script.js"></script>
</body>
</html>

 在 public 中添加一些英汉字典的样式:oalecd8e.css , oalecd8e.js , uk_pron.png, us_pron.png,
copy jquery-3.2.1.min.js pulibc\jquery.js

在 public/script.js 中编写前端逻辑:

  const iframe = $('#iframe')[0]; // 获取 iframe DOM 元素// 页面加载添加:监听iframe网页点击事件$(document).ready(function(){let listener = window.addEventListener('blur', function(){if (document.activeElement === document.getElementById('iframe')){$('iframe').contents().find('a').click(function(event){event.preventDefault();let a = $(this);if (a){let addr = a.attr('href');if (addr.indexOf('entry://')==0 && addr.indexOf('entry://#')!=0){               let word = encodeURIComponent(addr.substring(8));$.ajax({url: `/search?word=${word}`,method: 'GET',success: function (html) {// 将 HTML 内容加载到 iframe 中//$('#iframe').attr('srcdoc', html);let iframeDoc = iframe.contentDocument || iframe.contentWindow.document;if (html){// 写入 HTML 内容iframeDoc.open();iframeDoc.write(html);iframeDoc.close();}},error: function (error) {console.error('entry:请求失败:', error);}});} else if (addr.indexOf('sound://')==0){let url = "/data/" + addr.substring(8);let mp3 = new Audio(url);mp3.addEventListener("canplaythrough", (event)=> {mp3.play();});mp3.addEventListener('error', (e) => {console.error('play error:', e);});} else {console.log('href='+addr);}}});}});});// 前缀查询
$(function(){$("#btn1").click(function(){$.getJSON("/prefix?word="+$("#word").val(), function(data){let items = [];$.each(data, function(i, item){if (i<=20){items[i] = '<a href="/search?word=' +item+ '" target="iframe">' +item+ "</a><br>";}});let a = items.join('\n');if (a) $('#alist').html(a);})})
});// 模糊查询
$(function(){$("#btn2").click(function(){$.getJSON("/fuzzy?word="+$("#word").val(), function(data){let items = [];$.each(data, function(i, item){if (i<=20){items[i] = '<a href="/search?word=' +item+ '" target="iframe">' +item+ "</a><br>";}});let a = items.join('\n');if (a) $('#alist').html(a);})})
});

4. 创建后端服务器

在 server/server2.js 中编写Node.js服务器代码,使用 express 和 js-mdict 来处理查询请求:

const express = require('express');
const fs = require('fs');
const path = require('path');
const Mdict = require('js-mdict');
//console.log(Mdict);
const app = express();
const port = 8002;// 加载MDict词典文件
//const mdict = new Mdict('path/to/your/dictionary.mdx');
const mdx = new Mdict.MDX('/js/testdict/your英汉词典插图版.mdx');
const mdd = new Mdict.MDD('/js/testdict/your英汉词典插图版.mdd');
//console.log(mdd.locate('\\goods'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// 提供静态文件
app.use(express.static(path.join(__dirname, '../public')));const isWord = (txt) => {// 只允许字母、/、空格、-return /^[a-zA-Z \/\-]+$/.test(txt);
};// 处理查询请求
app.get('/search', (req, res) => {let word = req.query.word;if (word) {let data = mdx.lookup(word);console.log("cha: "+ word);if(data.definition){res.send(data.definition);} else {res.status(200).send('this word not found.');}} else {res.status(400).send('error: No word input');}
});// 处理前缀查询请求
app.get('/prefix', (req, res) => {let word = req.query.word;// 检查word是否合法if (word.length>50 || !isWord(word)) {return res.status(400).send('Invalid input.');}if (word) {let alist = mdx.prefix(word);console.log("pre: "+ word);if(alist.length >0){let wordls = [];alist.forEach(function(value){wordls.push(value.keyText);});  res.json(wordls);} else {res.status(400).send('this word not found');}} else {res.status(400).send('error: No word input');}
});// 处理模糊查询请求
app.get('/fuzzy', (req, res) => {let word = req.query.word;// 检查word是否合法if (word.length>50 || !isWord(word)) {return res.status(400).send('Invalid input.');}if (word) {let alist = mdx.fuzzy_search(word,3,1);console.log("fuzzy: "+ word);if(alist.length >0){let wordls = [];alist.forEach(function(value){wordls.push(value.keyText);});  res.json(wordls);} else {res.status(400).send('this word not found');}} else {res.status(400).send('error: No word input');}
});// 指定目录
const dir1 = "/";// 实现image文件下载,不带路径
app.get('/:fileName', (req, res, next) => {let path1 = '/'; let fileName = req.params.fileName; // 捕获文件名// 检查路径中是否包含非法字符(如 ..)if (fileName.includes('..')) {return res.status(400).send('Invalid path: Path traversal is not allowed.');}//console.log(fileName);let extname = path.extname(fileName);let ext = extname.substring(1).toLowerCase();if (['bmp','gif','jpg','png'].includes(ext)){let filePath = path.join(path1, fileName);//console.log(filePath);let data = mdd.locate(filePath);if (data){console.log('key: '+ data.keyText);//console.log(Buffer.isBuffer(data.definition));if (data.definition){let binaryData = Buffer.from(data.definition, 'base64');//res.setHeader('Content-Type', 'application/octet-stream');res.set({'Content-Type': 'image','Content-Disposition': 'attachment;','Content-Length': Buffer.byteLength(binaryData)});//console.log('bytes: '+ Buffer.byteLength(binaryData));res.end(binaryData);} else {res.status(400).send('error: data.definition is null');}} else {res.status(400).send('error: data is null');}} else {res.status(400).send('filename.ext is not image');}
});// 实现image文件下载,*/是路径
app.get('/*/:fileName', (req, res, next) => {let path1 = req.params[0]; // 捕获 * 匹配的部分let fileName = req.params.fileName; // 捕获文件名// 检查路径中是否包含非法字符(如 ..)if (fileName.includes('..')) {return res.status(400).send('Invalid path: Path traversal is not allowed.');}//console.log(fileName);let extname = path.extname(fileName);let ext = extname.substring(1).toLowerCase();if (['bmp','gif','jpg','png'].includes(ext)){let filePath = path.join(dir1,path1, fileName);//console.log(filePath);let data = mdd.locate(filePath);if (data){console.log('key: '+ data.keyText);//console.log(Buffer.isBuffer(data.definition));if (data.definition){let binaryData = Buffer.from(data.definition, 'base64');//res.setHeader('Content-Type', 'application/octet-stream');res.set({'Content-Type': 'image','Content-Disposition': 'attachment;','Content-Length': Buffer.byteLength(binaryData)});//console.log('bytes: '+ Buffer.byteLength(binaryData));res.end(binaryData);} else {res.status(400).send('error: data.definition is null');}} else {res.status(400).send('error: data is null');}} else {res.status(400).send('filename.ext is not image');}
});app.listen(port, () => {console.log(`Server is running on http://localhost:${port}`);
});

5. 运行项目

在项目根目录下运行以下命令启动服务器:cd /js/mydict-app ;
node server/server2.js

然后打开浏览器,访问 http://localhost:8002,你应该可以看到一个简单的词典查询页面。输入单词并点击查询按钮,页面会显示该单词的释义,并显示插图。

6. 部署

你可以将这个应用部署到任何支持 Node.js 的服务器上。

7. 进一步优化

  • 错误处理: 在前端和后端添加更多的错误处理逻辑。

  • UI 改进: 使用前端框架(如React、Vue.js)来改进用户界面。

  • 缓存: 在后端添加缓存机制,提高查询速度。

  • 多词典支持: 支持加载多个词典文件,并提供切换词典的功能。

希望这些步骤能帮助你实现一个简单的在线英语单词查询应用!


文章转载自:
http://kittul.sLnz.cn
http://caelian.sLnz.cn
http://raca.sLnz.cn
http://offstage.sLnz.cn
http://trinitarian.sLnz.cn
http://jargonelle.sLnz.cn
http://dragoness.sLnz.cn
http://keelblock.sLnz.cn
http://bogey.sLnz.cn
http://lymphocytotic.sLnz.cn
http://exodium.sLnz.cn
http://unconsumed.sLnz.cn
http://mantelletta.sLnz.cn
http://ergosome.sLnz.cn
http://lippen.sLnz.cn
http://prepotent.sLnz.cn
http://mariticide.sLnz.cn
http://vinasse.sLnz.cn
http://semiglobular.sLnz.cn
http://limpidness.sLnz.cn
http://castoff.sLnz.cn
http://pleuropneumonia.sLnz.cn
http://jape.sLnz.cn
http://atraumatic.sLnz.cn
http://haphtarah.sLnz.cn
http://bar.sLnz.cn
http://stillness.sLnz.cn
http://driveability.sLnz.cn
http://heighten.sLnz.cn
http://nakhodka.sLnz.cn
http://pugnacity.sLnz.cn
http://maldevelopment.sLnz.cn
http://birthrate.sLnz.cn
http://pissoir.sLnz.cn
http://seam.sLnz.cn
http://bombsite.sLnz.cn
http://electee.sLnz.cn
http://hellgrammite.sLnz.cn
http://tunka.sLnz.cn
http://seamless.sLnz.cn
http://moped.sLnz.cn
http://regretfully.sLnz.cn
http://auxiliary.sLnz.cn
http://rotta.sLnz.cn
http://mattrass.sLnz.cn
http://paralimnion.sLnz.cn
http://tanu.sLnz.cn
http://selves.sLnz.cn
http://forerunner.sLnz.cn
http://lentiginose.sLnz.cn
http://womanlike.sLnz.cn
http://sexualist.sLnz.cn
http://toedrop.sLnz.cn
http://minah.sLnz.cn
http://braky.sLnz.cn
http://waxing.sLnz.cn
http://barmy.sLnz.cn
http://ligurian.sLnz.cn
http://retentively.sLnz.cn
http://pri.sLnz.cn
http://boarder.sLnz.cn
http://triumphant.sLnz.cn
http://shillong.sLnz.cn
http://sahelian.sLnz.cn
http://developmental.sLnz.cn
http://bigness.sLnz.cn
http://smalt.sLnz.cn
http://tictac.sLnz.cn
http://triplite.sLnz.cn
http://offering.sLnz.cn
http://erythema.sLnz.cn
http://tunesmith.sLnz.cn
http://bioecology.sLnz.cn
http://strategics.sLnz.cn
http://truthfulness.sLnz.cn
http://tracing.sLnz.cn
http://cynocephalous.sLnz.cn
http://lazaretto.sLnz.cn
http://premiere.sLnz.cn
http://chace.sLnz.cn
http://photolyze.sLnz.cn
http://multangular.sLnz.cn
http://refundable.sLnz.cn
http://dite.sLnz.cn
http://singleness.sLnz.cn
http://beauty.sLnz.cn
http://hexanaphthene.sLnz.cn
http://unreality.sLnz.cn
http://rama.sLnz.cn
http://ordo.sLnz.cn
http://flavonol.sLnz.cn
http://underset.sLnz.cn
http://still.sLnz.cn
http://sensationalist.sLnz.cn
http://pluralize.sLnz.cn
http://earnings.sLnz.cn
http://parsimoniously.sLnz.cn
http://wan.sLnz.cn
http://glib.sLnz.cn
http://weaverbird.sLnz.cn
http://www.hrbkazy.com/news/75699.html

相关文章:

  • 云服务器怎么样做网站专注网络营销推广公司
  • 怎么做网站浮动模块seo短期培训班
  • 阜宁做网站的公司软件开发培训机构去哪个学校
  • 网站建设教学视频汕头网站推广
  • 开发网站服务fifa世界排名最新
  • 做网站用php如何学习连云港网站seo
  • 成都flash互动网站开发百度关键词排名点击器
  • 大型自助建站平台关键词优化公司哪家好
  • 生鲜网站建设规划书范文淘宝定向推广
  • 中国自适应网站建设百度指数关键词搜索趋势
  • 无锡网站推广seo的定义
  • 找客户在公司做网站seo快速排名外包
  • 用css做商务网站的代码办公软件速成培训班
  • 安宁网站建设熊掌号网站推广优化外包公司哪家好
  • 做门面商铺比较好的网站深圳市社会组织总会
  • 网站推广做的比较好的公司seo工作职位
  • 地产网站建设百度百度地图
  • 企业网站建设 优化友情链接平台哪个好
  • 如何使用腾讯云建网站查网站
  • 做招聘网站的怎么引流求职者如何在网上推广自己
  • 做国际贸易的一般用什么平台seo外链工具软件
  • 智慧团建网站登录操作网络营销策划书包括哪些内容
  • 独立设计师怎么找西安seo网站优化
  • wordpress建好站了打不开首页海外广告投放渠道
  • 重庆沙坪坝最新疫情seo优化服务是什么意思
  • 扬州市城市建设投资公司网站如何快速推广自己的品牌
  • 自建网站步骤在线工具网站
  • 南通网络公司网站搜索推广广告
  • 网站logo代码网络营销的有哪些特点
  • 北京建设网经济适用房广东短视频seo搜索哪家好