提交 1e76f881 编写于 作者: X xjh22222228

refactor: nav.config

上级 34e6b14b
......@@ -41,3 +41,4 @@ Thumbs.db
*.psd*
.eslintcache
nav.config.js
......@@ -104,6 +104,13 @@ server {
## 关于升级
在升级之前请保存根目录下的 `data` 文件夹,最好把 `nav.config.ts` 配置文件也保存一份以防万一, 升级完后将替换即可。
## 开发构建
``` bash
......@@ -136,6 +143,9 @@ Thank you for your [contribution](https://github.com/xjh22222228/nav/issues), me
<a href="https://github.com/Fechin">
<img src="https://avatars1.githubusercontent.com/u/2541482?s=460&v=4" width="30px" height="30px" />
</a>
<a href="https://github.com/setdiaoyong">
<img src="https://avatars1.githubusercontent.com/u/62551864?s=460&v=4" width="30px" height="30px" />
</a>
......@@ -145,6 +155,13 @@ Thank you for your [contribution](https://github.com/xjh22222228/nav/issues), me
## 支持
如果能帮到您,可以请作者喝杯咖啡~
项目成立于 2018 年到至今一直坚持维护和开源, 经过N次的迭代与优化, 如果项目能帮到您是我的荣幸。
您可以请作者喝杯咖啡,继续战斗下去(请备注Github名字)~
<img src="https://raw.sevencdn.com/xjh22222228/public/gh-pages/img/32.png" width="600">
感谢您的认可:
| --------------------------------------- |----------- |
| [aiyou9](https://github.com/aiyou9) | ¥20.00 |
// Copyright @ 2018-2021 xiejiahe. All rights reserved. MIT license.
import fs from 'fs'
import config from './nav.config.js'
import path from 'path'
const { description, title, keywords, tongjiUrl } = config.default
const htmlTemplate = `
<title>${title}</title>
<meta name="description" content="${description}">
<meta name="keywords" content="${keywords}">
`.trim()
const scriptTemplate = `
<script>
var _hmt = _hmt || [];
var hm = document.createElement('script');
hm.async = true;
hm.src = 'https://hm.baidu.com/hm.js?32c73f6240df008812d40821b82ea2b7';
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
</script>
`.trim()
try {
const htmlPath = path.join('.', 'src', 'index.html')
const readHtml = fs.readFileSync(htmlPath).toString()
let t = readHtml.replace('<!-- nav.config -->', htmlTemplate)
if (tongjiUrl) {
t = t.replace('<!-- nav.script -->', scriptTemplate)
}
fs.writeFileSync(htmlPath, t, { encoding: 'utf-8' })
fs.unlinkSync('./nav.config.js')
console.log('Build done!')
} catch (error) {
console.log(error)
}
......@@ -7,10 +7,16 @@ const c: IConfig = {
// 网站标题
title: '发现导航 - 精选实用导航网站',
// 默认主题: light | sim
theme: 'light',
// 网站描述
description: '发现导航 - 精选实用导航网站',
// 海报图, 只支持 sim 主题
// 网站关键字
keywords: '导航,前端资源,社区站点,设计师,实用工具,学习资源,运营,网络安全,node.js',
// 默认主题: Light | Sim
theme: 'Light',
// 海报图, 只支持 Sim 主题
// 请不要放在项目里头, 填写Url
posterImageUrl: 'assets/img/wallpaper.jpg',
......@@ -62,7 +68,7 @@ const c: IConfig = {
footerCopyright: '',
// 百度统计
tongjiUrl: 'https://hm.baidu.com/hm.js?4582be7af7e7c95ef75351e07c6c32ba',
baiduStatisticsUrl: 'https://hm.baidu.com/hm.js?4582be7af7e7c95ef75351e07c6c32ba',
indexLanguage: [
'英文',
......
{
"name": "nav",
"version": "5.0.0-beta.3",
"version": "5.0.0-beta.5",
"author": "xiejiahe",
"bugs": {
"url": "https://github.com/xjh22222228/nav/issues"
......@@ -12,8 +12,8 @@
"homepage": "https://github.com/xjh22222228/nav",
"scripts": {
"ng": "ng",
"start": "ng serve --open",
"build": "ng build --prod --base-href ./",
"start": "ng serve",
"build": "tsc nav.config.ts && ts-node build.mjs && ng build --prod --base-href ./",
"lint": "eslint --cache --ext .js,.ts ./src"
},
"private": true,
......
// Copyright @ 2018-2021 xiejiahe. All rights reserved. MIT license.
import config from '../../nav.config'
import { Component } from '@angular/core'
import { Router, ActivatedRoute } from '@angular/router'
import { queryString, setLocation } from '../utils'
......@@ -14,11 +13,7 @@ export class AppComponent {
constructor (private router: Router, private activatedRoute: ActivatedRoute) {}
ngOnInit() {
document.title = config.title
this.goRoute()
this.appendTongji()
this.activatedRoute.queryParams.subscribe(setLocation)
}
......@@ -31,17 +26,4 @@ export class AppComponent {
this.router.navigate(['/app'], { queryParams })
}
}
appendTongji() {
if (
document.getElementById('tongji_url') ||
window.location.hostname === 'localhost'
) return
const script = document.createElement('script')
script.src = config.tongjiUrl
script.id = 'tongji_url'
script.async = true
document.head.appendChild(script)
}
}
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1610844664805" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4151" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M383 646.085L399.025 637 533 871.915 516.975 881z" fill="#834038" p-id="4152"></path><path d="M449 502.193L467.122 499 534 874.807 515.878 878z" fill="#834038" p-id="4153"></path><path d="M520.148 455l17.852 0.184L533.852 876 516 875.816z" fill="#834038" p-id="4154"></path><path d="M593.107 560L611 564.338 533.893 878 516 873.662z" fill="#834038" p-id="4155"></path><path d="M363.23 632.467l26.373-20.207 36.475 28.236-60.264 28.554z" fill="#61CB69" p-id="4156"></path><path d="M371.964 658.54l41.068-19.459-23.45-18.153-19.233 14.736 1.615 22.876z m17.66-54.947l49.499 38.318-79.459 37.649-3.551-50.29 33.512-25.677z" fill="#834038" p-id="4157"></path><path d="M161.062622 555.070208a185.273 142.084 56 1 0 235.585948-158.904729 185.273 142.084 56 1 0-235.585948 158.904729Z" fill="#5DC861" p-id="4158"></path><path d="M166.073474 563.459414c50.076676 9.453707 105.051206-0.668111 152.139711-32.429708 45.230632-30.508446 74.674697-75.242139 85.783934-123.011032 50.392145 83.359394 42.246629 181.667261-20.29182 223.849977-63.431323 42.784967-159.435051 12.057293-217.630996-68.409796z" fill="#000000" opacity=".342" p-id="4159"></path><path d="M159.265872 399.805647a26.676 18.617 81 1 0 36.775588-5.824681 26.676 18.617 81 1 0-36.775588 5.824681Z" fill="#FFFFFF" opacity=".516" p-id="4160"></path><path d="M388.588271 632.614669C319.90085 678.944919 216.757081 644.248378 157.653747 556.624081S105.019234 360.369822 173.707484 314.039013c68.689079-46.331369 171.830631-11.634538 230.933965 75.989759 59.103335 87.624297 52.63673 196.253969-16.052349 242.585338z m-9.143922-13.556423c60.140873-40.565531 65.997297-138.940892 11.47487-219.773713-54.521867-80.831992-147.927769-112.254069-208.068642-71.688539-60.140044 40.564972-65.996468 138.940333-11.474601 219.772326 54.522426 80.832821 147.928329 112.254898 208.068373 71.689926z" fill="#834038" p-id="4161"></path><path d="M437.04 477.842l26.353-20.247 36.448 28.292-60.22 28.611z" fill="#7BCEF5" p-id="4162"></path><path d="M436.607 503.967l41.038-19.497-23.433-18.19-19.22 14.766 1.615 22.921z m17.648-55.057l49.462 38.395-79.4 37.724-3.55-50.39 33.488-25.729z" fill="#834038" p-id="4163"></path><path d="M182.851364 346.682884a215.438 162.591 69 1 0 303.583551-116.534806 215.438 162.591 69 1 0-303.583551 116.534806Z" fill="#7BCEF5" p-id="4164"></path><path d="M187.144506 353.533366c53.552778 23.826978 117.549185 26.940517 178.229112 3.647676 58.285293-22.373628 102.542526-64.900627 127.08478-115.671997 35.141143 106.990826 1.078819 215.357328-79.509711 246.292366-81.739634 31.376906-181.209115-28.471528-225.805115-134.267687z" fill="#000000" opacity=".342" p-id="4165"></path><path d="M219.122311 169.151336a21.475 31.053 4 1 0 42.845376 2.996041 21.475 31.053 4 1 0-42.845376-2.996041Z" fill="#FFFFFF" opacity=".516" p-id="4166"></path><path d="M415.134373 498.102313C325.949435 532.337203 218.57957 465.315573 174.30106 349.96611 130.020899 234.615138 164.965676 112.962964 254.150614 78.728074S450.708934 111.515606 494.987445 226.865069 504.319311 463.867423 415.135306 498.101954z m-6.850204-17.84539c78.086534-29.974612 109.733605-140.143263 68.886827-246.55276S339.088285 66.598494 261.001751 96.573106c-78.0856 29.974254-109.732314 140.143838-68.885893 246.552401 40.846779 106.409497 138.082711 167.105669 216.168311 137.131416z" fill="#834038" p-id="4167"></path><path d="M368.139 287.5a206.33 155.361 90 1 0 310.722 0 206.33 155.361 90 1 0-310.722 0Z" fill="#E384CA" p-id="4168"></path><path d="M368.139 296.67c39.553 39.64 95.49 64.36 157.5 64.36 59.565 0 113.525-22.808 152.744-59.738-5.281 107.602-72.671 192.707-155.028 192.707-83.533 0-151.668-87.552-155.216-197.329z" fill="#000000" opacity=".342" p-id="4169"></path><path d="M460.279811 140.512207a20.576 29.785 25 1 0 37.296378 17.391586 20.576 29.785 25 1 0-37.296378-17.391586Z" fill="#FFFFFF" opacity=".516" p-id="4170"></path><path d="M523.5 503C432.003 503 359 406.047 359 287.5S432.003 72 523.5 72 688 168.953 688 287.5 614.997 503 523.5 503z m0-18.34c80.11 0 146.222-87.801 146.222-197.16S603.61 90.34 523.5 90.34c-80.11 0-146.222 87.801-146.222 197.16S443.39 484.66 523.5 484.66z" fill="#834038" p-id="4171"></path><path d="M840.027 354.467c-11.121 52.738 0.351 98.97 34.385 138.738 34.033 39.768 24.416 63.596-28.812 71.519-53.228 7.922-94.155 35-122.923 81.321-28.81 46.289-54.074 45.499-75.827-2.329-21.752-47.827-58.556-77.335-110.37-88.491-51.812-11.156-57.77-35.468-18.065-72.953 39.739-37.525 58.013-82.833 54.74-135.99-3.24-53.197 18.341-67.433 64.663-42.773 46.363 24.692 94.421 26.19 144.21 4.455 49.746-21.77 69.121-6.235 58 46.503z" fill="#C3BB42" p-id="4172"></path><path d="M871.176 498.324c-5.864 1.882-12.672 3.405-20.425 4.571-52.214 7.852-92.296 35.128-120.385 81.918-28.129 46.756-52.926 45.878-74.426-2.593-21.5-48.47-57.712-78.449-108.599-89.9-10.842-2.44-19.644-5.479-26.405-9.115 37.194-36.628 54.766-80.646 52.643-132.114 5.822-16.485 8.97-33.979 9.44-52.486 10.16-10.835 28.05-9.19 53.655 4.922 45.58 25.135 92.752 26.8 141.547 4.958 48.755-21.876 67.819-6.095 57.07 47.244-10.75 53.338 0.656 100.163 34.183 140.515 0.58 0.698 1.147 1.392 1.702 2.08z" fill="#EFE15C" p-id="4173"></path><path d="M785.291 316.104c-52.164 22.94-103.06 21.29-151.839-4.976-39.603-21.315-53.388-12.126-50.545 34.103 3.494 56.188-15.696 104.409-57.235 144.001-34.202 32.592-30.469 47.78 13.585 57.404 54.514 11.91 93.633 43.588 116.574 94.402 18.549 41.085 34.191 41.59 58.968 1.357 30.033-48.875 73.165-77.652 128.911-85.964 45.84-6.835 51.964-22.21 22.857-56.53-35.835-42.253-48.031-91.694-36.438-147.488 9.462-45.535-2.3-55.06-44.838-36.309z m95.578 171.683c38.76 45.702 25.808 78.222-34.36 87.194-50.244 7.492-88.563 33.058-115.724 77.258-32.482 52.746-67.16 51.625-92.052-3.51-20.495-45.395-54.745-73.13-103.452-83.77-59.117-12.916-67.394-46.595-22.567-89.311 37.564-35.805 54.616-78.652 51.468-129.292-3.733-60.698 25.405-80.123 78.144-51.737 43.638 23.498 88.463 24.951 135.379 4.32 56.497-24.906 83.36-3.153 70.794 57.318-10.429 50.188 0.313 93.731 32.37 131.53z" fill="#834038" p-id="4174"></path><path d="M506.222 882.404c-9.157 21.177-12.71 39.47-10.659 54.88 2.972 18.528 12.358 22.73 23.522 17.828C530.63 950.04 537 921.467 537 906.583V876h-17.915l-12.863 6.404z" fill="#834038" p-id="4175"></path><path d="M507.79 866.424L537 865v18h-31z" fill="#E1AAB0" p-id="4176"></path></svg>
\ No newline at end of file
<div class="fixbar">
<div
class="wrapper dark-bg dark-border-color dark-action-hover"
(click)="toggleEditMode()"
nz-dropdown
[nzDropdownMenu]="menu"
nzPlacement="topLeft"
>
<img src="assets/img/theme.svg" />
</div>
<nz-dropdown-menu #menu="nzDropdownMenu">
<ul nz-menu nzSelectable>
<li
nz-menu-item
*ngFor="let themeItem of themeList"
(click)="toggleTheme(themeItem)"
>
{{ themeItem.name }}
</li>
</ul>
</nz-dropdown-menu>
<span *ngIf="isLogin" nz-tooltip nzTooltipTitle="同步数据">
<div
class="wrapper dark-bg dark-border-color dark-action-hover"
......@@ -8,7 +29,6 @@
<i class="iconfont iconwinfo-icon-tongbu"></i>
</div>
</span>
<span *ngIf="isLogin" nz-tooltip [nzTooltipTitle]="isEditing.value ? '关闭编辑模式' : '开启编辑模式'">
<div class="wrapper dark-bg dark-border-color dark-action-hover" (click)="toggleEditMode()">
......@@ -35,7 +55,7 @@
</div>
</span>
<div class="wrapper dark-bg dark-border-color dark-action-hover" (click)="scrollTop()">
<div class="wrapper dark-bg dark-border-color dark-action-hover" (click)="goTop()">
<i class="iconfont iconjiantouarrow483 arrow"></i>
</div>
</div>
......
// Copyright @ 2018-2021 xiejiahe. All rights reserved. MIT license.
import { Component, Output, EventEmitter, Input } from '@angular/core'
import { isDark as isDarkFn, randomBgImg } from '../../utils'
import { isDark as isDarkFn, randomBgImg, queryString } from '../../utils'
import { NzModalService } from 'ng-zorro-antd/modal'
import { NzMessageService } from 'ng-zorro-antd/message'
import { NzNotificationService } from 'ng-zorro-antd/notification'
......@@ -9,6 +9,8 @@ import { getToken } from '../../utils/user'
import { updateFileContent } from '../../services'
import { websiteList, isEditing } from '../../store'
import { DB_PATH } from '../../constants'
import { Router } from '@angular/router'
import { setAnnotate } from '../../utils/ripple'
@Component({
selector: 'app-fixbar',
......@@ -28,11 +30,22 @@ export class FixbarComponent {
syncLoading = false
isLogin = !!getToken()
isEditing = isEditing
themeList = [
{
name: '切换到 Light',
url: '/light'
},
{
name: '切换到 Sim',
url: '/sim'
}
]
constructor(
private message: NzMessageService,
private notification: NzNotificationService,
private modal: NzModalService
private modal: NzModalService,
private router: Router
) {}
ngOnInit() {
......@@ -40,6 +53,11 @@ export class FixbarComponent {
document.body.classList.add('dark-container')
this.toggleZorroDark(true)
}
const url = this.router.url.split('?')[0]
this.themeList = this.themeList.filter(t => {
return t.url !== url
})
}
toggleZorroDark(dark: boolean) {
......@@ -47,19 +65,30 @@ export class FixbarComponent {
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = '/assets/ng-zorro-antd.dark.css'
link.id = 'NG-ZORRO-DARK'
link.className = 'NG-ZORRO-DARK'
document.body.append(link)
} else {
const findLink = document.getElementById('NG-ZORRO-DARK')
findLink.parentNode.removeChild(findLink)
const findLink = document.querySelectorAll('.NG-ZORRO-DARK')
findLink.forEach(child => {
child.parentNode.removeChild(child)
})
}
}
toggleTheme(theme) {
this.router.navigate([theme.url], {
queryParams: queryString()
})
setTimeout(() => {
setAnnotate()
}, 100)
}
toggleEditMode() {
this.isEditing.value = !this.isEditing.value
}
scrollTop() {
goTop() {
if (this.selector) {
const el = document.querySelector(this.selector)
if (el) {
......
......@@ -19,8 +19,10 @@ export class SearchEngineComponent {
constructor (private router: Router) {}
inputFocus() {
const inputEl = document.getElementById('search-engine-input')
inputEl?.focus?.()
setTimeout(() => {
const inputEl = document.getElementById('search-engine-input')
inputEl?.focus?.()
}, 100)
}
ngAfterViewInit() {
......
......@@ -31,11 +31,10 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="renderer" content="webkit">
<meta name="description" content="发现导航 - 精选实用导航网站">
<meta name="keywords" content="导航,前端资源,社区站点,设计师,实用工具,学习资源,运营,网络安全,node.js">
<link rel="icon" href="assets/logo.png">
<link rel ="apple-touch-icon" href="assets/logo.png">
<link rel="stylesheet" href="//at.alicdn.com/t/font_2267418_40eo6u8a0ak.css">
<!-- nav.config -->
</head>
<body>
......@@ -45,5 +44,9 @@
<script src="./assets/js/jquery.min.js"></script>
<script src="./assets/js/ripple.min.js"></script>
<!-- nav.script -->
<!-- nav.seo -->
</body>
</html>
// Copyright @ 2018-2021 xiejiahe. All rights reserved. MIT license.
export type ThemeType =
| 'light'
| 'sim'
| 'Light'
| 'Sim'
export interface INavFourProp {
icon?: string | null
......@@ -43,12 +43,14 @@ export interface ISearchEngineProps {
export interface IConfig {
title: string
description: string
keywords: string
theme: ThemeType
posterImageUrl: string
searchEngineList: ISearchEngineProps[]
gitRepoUrl: string,
footerCopyright: string|null
tongjiUrl: string
baiduStatisticsUrl: string
indexLanguage: string[]
appLanguage: string[]
backgroundLinear: string[]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册