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

企业网站功能间联系高级seo

企业网站功能间联系,高级seo,web程序设计——asp.net实用网站开发,夺宝网站是怎么做推广的HBuilderx 插件开发变量名称翻译 ,中文转(小驼峰,大驼峰,下划线,常量,CSS类名) 插件开发文档 工具HBuilderx ,创建项目 创建成功后目录 插件需求 开发时 用来将中文转为&#xff0…

HBuilderx 插件开发变量名称翻译 ,中文转(小驼峰,大驼峰,下划线,常量,CSS类名)

插件开发文档
工具HBuilderx ,创建项目

在这里插入图片描述
在这里插入图片描述

创建成功后目录

在这里插入图片描述

插件需求 开发时 用来将中文转为(小驼峰,大驼峰,下划线,常量,CSS类名)
  1. package.json 文件中配置插件菜单,通过在插件package.json文件中contributes节点下定义的一些JSON格式的配置项。(注意:配置时一定要注意json格式)
{"id": "plugin-fyi","name": "fyi","description": "plugin-fyi","displayName": "plugin-fyi","version": "0.0.0","publisher": "your name","engines": {"HBuilderX": "^2.7.0"},"categories": ["Other"],"main": "./extension","activationEvents": ["*"],"contributes": {"commands": [{"command": "fyi.smallHump","title": "小驼峰"},{"command": "fyi.bigHump","title": "大驼峰"},{"command": "fyi.underline","title": "下划线"},{"command": "fyi.constant","title": "常量"},{"command": "fyi.cssClassName","title": "CSS类名"}],"menus": {"editor/context": [{"group": "z_commands"}, {"title": "小驼峰","command": "fyi.smallHump","group": "z_commands"},{"title": "大驼峰","command": "fyi.bigHump","group": "z_commands"},{"title": "下划线","command": "fyi.underline","group": "z_commands"},{"title": "常量","command": "fyi.constant","group": "z_commands"},{"title": "CSS类名","command": "fyi.cssClassName","group": "z_commands"},{"group": "z_commands"}]},"extensionDependencies": ["plugin-manager"]},"dependencies": {"axios": "^1.7.9","js-md5": "^0.8.3"}
}
  1. 运行插件
    在这里插入图片描述
  2. 运行成功 会打开新的编辑器
    在这里插入图片描述
  3. 打开一个项目 或者新建一个项目 (我这里是打开一个项目)然后右键查看
    在这里插入图片描述
中文翻译需要用到 百度翻译
  1. 百度翻译开放平台
    在这里插入图片描述
  2. 申请秘钥 APPID密钥
    在这里插入图片描述
开始添加逻辑处理
  1. 新建js文件夹 用来处理 翻译 转换的逻辑

  2. 在这里插入图片描述

  3. extension.js 文件 该文件为主文件 需要与 package.json 中的 main 保持一致

	const hx = require("hbuilderx");const commands = require('./js/index')//该方法将在插件激活的时候调用function activate(context) {for (const c of commands) {//订阅销毁钩子,插件禁用的时候,自动注销该command。context.subscriptions.push(c);}}//该方法将在插件禁用的时候调用(目前是在插件卸载的时候触发)function deactivate() {}module.exports = {activate,deactivate}
  1. 调用百度翻译需要用到 axiosMD5.js 安装:
npm install axios
npm install js-md5 
  1. util.js 调用百度api 翻译 *******请更换代码中的 appid 和密钥********
const axios = require('axios');
const hx = require("hbuilderx");
const md5 = require('js-md5');// 封装百度翻译 API 请求函数
module.exports = async function (text) {try {// 在状态栏显示正在转换的消息hx.window.setStatusBarMessage(`正在转换...`);// 百度翻译 API 的配置信息const appid = '你上面申请的appid';const secretKey = '你上面申请的密钥';// 生成随机数 saltconst salt = Math.floor(Math.random() * (65536 - 32768 + 1)) + 32768;// 拼接用于生成签名的字符串const signStr = appid + text + salt + secretKey;// 计算 MD5 哈希值作为签名const sign = md5(signStr);// 发送请求到百度翻译 APIconst response = await axios({method: 'post',url: 'http://api.fanyi.baidu.com/api/trans/vip/translate',data: {q: text,from: 'auto',to: 'en',appid: appid,salt: salt,sign: sign},headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }});const data = response.data;// 检查响应数据是否包含必要的字段if (data.from && data.to && data.trans_result) {// 解析出翻译结果return data.trans_result[0].dst;} else {// 处理识别失败的情况const errorMessage = `识别失败,错误码: ${data.error_code}`;hx.window.showErrorMessage(errorMessage);return {msg: "识别失败",code: data.error_code};}} catch (error) {// 处理请求过程中可能出现的错误const errorMessage = `请求翻译 API 时发生错误: ${error.message}`;hx.window.showErrorMessage(errorMessage);console.error(errorMessage, error);return {msg: "请求翻译 API 时发生错误",code: -1};} finally {// 清除状态栏的消息hx.window.clearStatusBarMessage();}
};
  1. index.js 转换方法文件
const hx = require("hbuilderx");
const util = require("./util");// 定义字符串转换类型的映射对象
const conversionFunctions = {'1': toCamelCase,'2': toPascalCase,'3': toSnakeCase,'4': toConstantCase,'5': toCssClassName
};// 注册命令的函数
function registerCommand(method, type) {return hx.commands.registerCommand(method, async () => {try {// 获取当前活动的文本编辑器const activeEditor = await hx.window.getActiveTextEditor();if (!activeEditor) {return;}const editor = await activeEditor;const selections = editor.selections;// 遍历每个选中区域for (const selection of selections) {const selectText = editor.document.getText(selection);let text = await util(selectText);// 根据类型获取对应的转换函数const convertFunction = conversionFunctions[type] || toCamelCase;const str = convertFunction(text);// 替换选中区域的文本editor.edit(editBuilder => editBuilder.replace(selection, str));}} catch (error) {console.error('执行命令时发生错误:', error);}});
}// 小驼峰转换函数
function toCamelCase(str) {const words = str.split(' ');return words.map((word, index) => {if (index === 0) {return word.toLowerCase();}return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();}).join('');
}// 大驼峰转换函数
function toPascalCase(str) {return str.split(' ').map(word => {return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();}).join('');
}// 下划线转换函数
function toSnakeCase(str) {return str.replace(/\s/g, '_').toLowerCase();
}// 常量转换函数
function toConstantCase(str) {return str.replace(/\s/g, '_').toUpperCase();
}// CSS类名转换函数
function toCssClassName(str) {return str.toLowerCase().replace(/\s/g, '-');
}// 注册各个命令
const smallHump = registerCommand('fyi.smallHump', '1');
const bigHump = registerCommand('fyi.bigHump', '2');
const underline = registerCommand('fyi.underline', '3');
const constant = registerCommand('fyi.constant', '4');
const cssClassName = registerCommand('fyi.cssClassName', '5');// 导出注册的命令
module.exports = [smallHump,bigHump,underline,constant,cssClassName
];
  1. 至此 全部开发结束。重新运行插件
    在这里插入图片描述
  2. 测试正常,开发结束。
优化
  1. 菜单合并 package.json
{"id": "plugin-fyi","name": "fyi","description": "plugin-fyi","displayName": "plugin-fyi","version": "0.0.0","publisher": "your name","engines": {"HBuilderX": "^2.7.0"},"categories": ["Other"],"main": "./extension","activationEvents": ["*"],"contributes": {"commands": [{"command": "fyi.smallHump","title": "小驼峰"},{"command": "fyi.bigHump","title": "大驼峰"},{"command": "fyi.underline","title": "下划线"},{"command": "fyi.constant","title": "常量"},{"command": "fyi.cssClassName","title": "CSS类名"}],"menus": {"editor/context": [{"id": "fyi","title": "來啊快樂啊","group": "assist"},{"title": "小驼峰","command": "fyi.smallHump","group": "fyi@1"},{"title": "大驼峰","command": "fyi.bigHump","group": "fyi@2"},{"title": "下划线","command": "fyi.underline","group": "fyi@3"},{"title": "常量","command": "fyi.constant","group": "fyi@4"},{"title": "CSS类名","command": "fyi.cssClassName","group": "fyi@5"}]},"extensionDependencies": ["plugin-manager"]},"dependencies": {"axios": "^1.7.9","js-md5": "^0.8.3"}
}

在这里插入图片描述

  1. 配置快捷键 点击工具 ----自定义快捷键
    在这里插入图片描述
  2. 添加代码 保存
    在这里插入图片描述
    在这里插入图片描述
  3. 快捷键使用正常。
完结。
http://www.dinnco.com/news/5434.html

相关文章:

  • 网站有利于seo的细节如何制作自己的网站教程
  • 乡镇可以做门户网站长沙 建站优化
  • 武昌网站建设公司网站推广软件费用是多少
  • 石狮网站建设公司哪家好打开全网搜索
  • 做网站和做微信小程序网络营销中的seo与sem
  • 深圳制作网站制作公司哪家好建站平台
  • 外贸网站怎样注册山东进一步优化
  • mvc中手把手做网站海淀区seo引擎优化多少钱
  • 给一个网站怎么做安全测试就业seo好还是sem
  • 新津网站建设zoho crm
  • ps制作网站导航图片系统开发
  • 钓鱼网站怎么做网站建设开发简介
  • 高端网站建设企业公司seo课程简介
  • ecshop的301重定向优化插件解决伪静态后重复页面提高网站权重广州关键词快速排名
  • 关于网站开发制作的相关科技杂志的网站网络营销所学课程
  • 龙岗住房和建设局网站官网线上培训平台
  • 2018钓鱼网站建设seo招聘信息
  • 做外语网站的公司网络优化工程师吃香吗
  • 长沙网站建设网店怎么推广和宣传
  • 广元网站建设价格高端网站建设企业
  • 网站建设与开发的收获与体会重庆网络推广专员
  • java 网站开发开源抖音代运营公司
  • eclipse做购物网站百度账号登录
  • 昆明网站建设公司哪家好台州seo排名扣费
  • 别人帮做的网站怎么修改病句收录网
  • wordpress网页北京seo公司wyhseo
  • seo网站运营网站怎么推广
  • 网址地址seo分析师
  • 惠州网站建设制作郑州模板网站建设
  • 网站域名需icp备案市场推广方案范文