anzhuo 发布的文章

function checkDeviceAndAlert() {
    const userAgent = navigator.userAgent || navigator.vendor || window.opera;
    
    const mobileRegex = /android|iphone|ipad|ipod|blackberry|iemobile|opera mini|mobile|windows phone|phone|webos|kindle|tablet/i;

    const isMobile = mobileRegex.test(userAgent.toLowerCase());
    
    if (isMobile) {
        alert("移动设备访问");
    } else {
        alert("电脑设备访问");
    }
}

window.addEventListener('DOMContentLoaded', checkDeviceAndAlert);

type NumOrStr = number | string;

function safeAdd(a: NumOrStr, b: NumOrStr): number {
    return Number(a) + Number(b); 
}
console.log(safeAdd(1, 1)); 
console.log(safeAdd("1", "1")); 
console.log(safeAdd(1, "1")); 

废话

考虑到我上一篇推荐Hexo的原因,这次出一个Hexo部署教程罢。(

项目简介

Hexo是一个快速、简洁且高效的博客框架,它使用Markdown解析文章,能在几秒内生成静态网页。

部署

先装nodejs,到官网.(或者搜索引擎搜索nodejs)
hexo本身就是node开发的,所以必须装,你连核心都没有就装壳子是不是太蠢了。(
到官网选下载lts版本,并按照提示安装。
装完后打开CMD(不会搜)输入下面这两条查看是否完成:

node --version
npm --version

如果显示版本号,说明安装成功力。
下面就是装git了,应该有人还不知道罢。这边就不做介绍了,感兴趣的自己查查这个工具。
访问git官网然后下载,安装完输入下面这个命令配置用户信息:

git config --global user.name "你的用户名"
git config --global user.email "你的邮箱"

接下来就是安装hexo了,环境配置完成后输入下面的命令:

# 使用npm安装hexo命令行工具
npm install -g hexo-cli

# 验证安装
hexo --version

初始化博客项目。

# 创建并进入博客文件夹
hexo init my-blog
cd my-blog

# 安装依赖
npm install

然后搞一下本地预览。

hexo g
hexo s

浏览器中访问 http://localhost:4000,没有其他事故的话,你应该能正常访问。
到此,你就部署完了,到时候你就可以去hexo的官网主题挑挑然后按照文档去搭建力。

废话

脑子抽了,想了这个文章。但这个确实适合某些人,比如想要静态效果的站长。但也有没钱买云服务的人(其实更推荐你用Hexo.io

该项目简介

VitePress是一个基于Vite的静态站点生成器,专为技术文档设计。

准备

首先确保你的系统已安装Node.js(版本16或更高),然后按以下步骤操作:

# 创建项目目录
mkdir my-vitepress-blog
cd my-vitepress-blog

# 初始化项目
npm init -y

# 安装VitePress
npm add -D vitepress

# 安装Markdown支持(可选但推荐)
npm add -D @vue/theme

创建基本目录结构(也可以看看文档的,或者你直接看文档新手模式):

114514/
├── docs/
│   ├── .vitepress/
│   │   └── config.js
│   ├── index.md
│   └── blog/
│       └── first-post.md
├── package.json
└── package-lock.json

开始

编辑 .vitepress/config.js文件,配置博客基本信息:

export default {
  title: '我的垃圾桶',
  description: '发史的地方。',
  themeConfig: {
    nav: [
      { text: '首页', link: '/' },
      { text: '博客', link: '/blog/' }
    ],
    sidebar: {
      '/blog/': [
        {
          text: '文章列表',
          items: [
            { text: '第一篇博客', link: '/blog/first-post' }
          ]
        }
      ]
    },
    socialLinks: [
      { icon: 'github', link: 'https://github.com/yourusername' }
    ]
  }
}

然后就是创建首页与博客文章力(喜

---
layout: home
hero:
  name: 垃圾桶
  text: 阿爸阿爸
  actions:
    - theme: brand
      text: 查看博客
      link: /blog/
    - theme: alt
      text: 关于我
      link: /about/
features:
  - title: 技术分享
    details: 分享前端开发、后端架构等技术内容
  - title: 学习笔记
    details: 记录学习过程中的心得与总结
  - title: 项目实践
    details: 实际项目中的经验与解决方案
---

创建第一篇博客文章 docs/blog/first-post.md(其实这个first-post可以改成自己的。)

---
title: 我的第一篇博客
date: 1145-1-10
description: 这是我的第一篇使用VitePress搭建的博客文章
---

# 欢迎来到我的博客

这是我的第一篇博客文章,使用VitePress搭建。

## 主要内容

这里可以开始写你的博客内容...

最后在说一句废话

反正你需要就可以搞啦,如果你想要搞静态博客我还是推荐hexo。