mirror of
https://github.com/Fechin/reference.git
synced 2026-11-20 21:23:11 +03:00
feat: fix code highlighting and upgrade dependencies
- Fix markdown-it-highlightjs configuration for Hexo 7.0+ - Create custom highlight.js instance to handle unknown languages gracefully - Eliminate 'Could not find language' warning messages - Upgrade ESLint to v9 with flat config format - Update Fuse.js from 6.4.6 to 7.1.0 - Update multiple dependencies to latest versions Technical changes: - Set syntax_highlighter to empty in _config.yml - Add langPrefix: 'hljs language-' configuration - Migrate ESLint to eslint.config.js (flat config) - Update Service Worker for new Fuse.js version
This commit is contained in:
1 parent
3b60a4c9fa
commit
8fd81decca
18 files changed
+756
-769
No files matched your search
@@ -1,13 +0,0 @@
|
||||
node_modules/
|
||||
public/
|
||||
themes/coo/source/js/fuse_6.4.6.js
|
||||
themes/coo/scripts/
|
||||
*.min.js
|
||||
gulpfile.js
|
||||
.eslintrc.js
|
||||
.prettierrc.js
|
||||
.stylelintrc.js
|
||||
.commitlintrc.js
|
||||
.lintstagedrc.js
|
||||
postcss.config.js
|
||||
tailwind.config.js
|
||||
@@ -1,52 +0,0 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
es2022: true,
|
||||
node: true
|
||||
},
|
||||
extends: ['eslint:recommended', 'prettier'],
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module'
|
||||
},
|
||||
rules: {
|
||||
// Error level rules
|
||||
'no-console': 'warn',
|
||||
'no-debugger': 'error',
|
||||
'no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
argsIgnorePattern: '^_',
|
||||
varsIgnorePattern: '^_'
|
||||
}
|
||||
],
|
||||
|
||||
// ES6+ best practices
|
||||
'prefer-const': 'error',
|
||||
'no-var': 'error',
|
||||
'object-shorthand': 'error',
|
||||
'prefer-template': 'error',
|
||||
'prefer-arrow-callback': 'error',
|
||||
|
||||
// Best practices
|
||||
eqeqeq: ['error', 'always'],
|
||||
curly: ['error', 'all'],
|
||||
'no-eval': 'error',
|
||||
'no-implied-eval': 'error',
|
||||
'no-new-func': 'error',
|
||||
'no-script-url': 'error',
|
||||
|
||||
// Function related
|
||||
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
|
||||
'no-loop-func': 'error',
|
||||
|
||||
// Objects and arrays
|
||||
'dot-notation': 'error'
|
||||
},
|
||||
|
||||
globals: {
|
||||
hexo: 'readonly',
|
||||
Utils: 'readonly',
|
||||
Fuse: 'readonly'
|
||||
}
|
||||
};
|
||||
@@ -45,6 +45,7 @@ render_drafts: false
|
||||
post_asset_folder: false
|
||||
relative_link: false
|
||||
future: true
|
||||
syntax_highlighter: # empty to disable built-in syntax highlighting
|
||||
highlight:
|
||||
enable: false
|
||||
|
||||
@@ -132,6 +133,7 @@ markdown:
|
||||
linkify: false
|
||||
typographer: false
|
||||
quotes: "“”‘’"
|
||||
langPrefix: "hljs language-"
|
||||
anchors:
|
||||
level: 2
|
||||
collisionSuffix: ""
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
const js = require('@eslint/js');
|
||||
const globals = require('globals');
|
||||
|
||||
module.exports = [
|
||||
js.configs.recommended,
|
||||
{
|
||||
languageOptions: {
|
||||
ecmaVersion: 2022,
|
||||
sourceType: 'module',
|
||||
globals: {
|
||||
...globals.browser,
|
||||
...globals.node
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
'no-unused-vars': 'warn',
|
||||
'no-console': 'off'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*.js'],
|
||||
languageOptions: {
|
||||
sourceType: 'script',
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.browser
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['source/sw.js'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.serviceworker
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['themes/coo/scripts/**/*.js'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
hexo: 'readonly'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['themes/coo/source/js/main.js'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.browser,
|
||||
Fuse: 'readonly'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
ignores: [
|
||||
'node_modules/**',
|
||||
'public/**',
|
||||
'db.json',
|
||||
'.deploy_git/**',
|
||||
'themes/coo/source/js/fuse_*.js'
|
||||
]
|
||||
}
|
||||
];
|
||||
+32
-32
@@ -27,11 +27,11 @@
|
||||
"commit": "cz"
|
||||
},
|
||||
"hexo": {
|
||||
"version": "5.4.2"
|
||||
"version": "7.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"gulp": "^5.0.0",
|
||||
"gulp-cli": "^3.0.0",
|
||||
"gulp": "^5.0.1",
|
||||
"gulp-cli": "^3.1.0",
|
||||
"gulp-ext-replace": "^0.3.0",
|
||||
"gulp-htmlclean": "^2.7.22",
|
||||
"gulp-htmlmin": "^5.0.1",
|
||||
@@ -39,58 +39,58 @@
|
||||
"gulp-postcss": "^10.0.0",
|
||||
"gulp-uglify-es": "^3.0.0",
|
||||
"gulp-version-number": "^0.2.4",
|
||||
"hexo": "^5.4.0",
|
||||
"hexo": "^7.3.0",
|
||||
"hexo-browsersync": "^0.3.0",
|
||||
"hexo-excerpt": "^1.2.1",
|
||||
"hexo-excerpt": "^1.3.1",
|
||||
"hexo-filter-nofollow": "^2.0.2",
|
||||
"hexo-generator-index": "^2.0.0",
|
||||
"hexo-generator-sitemap": "^2.2.0",
|
||||
"hexo-log": "^3.0.0",
|
||||
"hexo-pagination": "^2.0.0",
|
||||
"hexo-generator-index": "^4.0.0",
|
||||
"hexo-generator-sitemap": "^3.0.1",
|
||||
"hexo-log": "^4.1.0",
|
||||
"hexo-pagination": "^4.0.0",
|
||||
"hexo-related-popular-posts": "^5.0.1",
|
||||
"hexo-renderer-ejs": "^2.0.0",
|
||||
"hexo-renderer-markdown-it": "^5.0.0",
|
||||
"hexo-renderer-stylus": "^2.0.1",
|
||||
"hexo-server": "^2.0.0",
|
||||
"markdown-it-abbr": "^1.0.4",
|
||||
"markdown-it-anchor": "^8.4.1",
|
||||
"hexo-renderer-stylus": "^3.0.1",
|
||||
"hexo-server": "^3.0.0",
|
||||
"markdown-it-abbr": "^2.0.0",
|
||||
"markdown-it-anchor": "^9.2.0",
|
||||
"markdown-it-attrs": "^4.3.1",
|
||||
"markdown-it-checkbox": "^1.1.0",
|
||||
"markdown-it-emoji": "^2.0.0",
|
||||
"markdown-it-footnote": "^3.0.3",
|
||||
"markdown-it-emoji": "^3.0.0",
|
||||
"markdown-it-footnote": "^4.0.0",
|
||||
"markdown-it-highlight-lines": "^1.0.2",
|
||||
"markdown-it-highlightjs": "^4.2.0",
|
||||
"markdown-it-ins": "^3.0.1",
|
||||
"markdown-it-ins": "^4.0.0",
|
||||
"markdown-it-shortcode-tag": "^1.1.0",
|
||||
"markdown-it-sub": "^1.0.0",
|
||||
"markdown-it-sup": "^1.0.0",
|
||||
"markdown-it-sub": "^2.0.0",
|
||||
"markdown-it-sup": "^2.0.0",
|
||||
"markdown-it-task-lists": "^2.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^19.5.0",
|
||||
"@commitlint/config-conventional": "^19.5.0",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"@commitlint/cli": "^19.8.1",
|
||||
"@commitlint/config-conventional": "^19.8.1",
|
||||
"autoprefixer": "^10.4.21",
|
||||
"commitizen": "^4.3.1",
|
||||
"cssnano": "^7.0.7",
|
||||
"cz-conventional-changelog": "^3.3.0",
|
||||
"eslint": "^8.57.1",
|
||||
"eslint": "^9.29.0",
|
||||
"eslint-config-prettier": "^10.1.5",
|
||||
"gulp-clean-css": "^4.3.0",
|
||||
"gulp-filesize": "^0.0.6",
|
||||
"gulp-javascript-obfuscator": "^1.1.6",
|
||||
"gulp-replace": "^1.1.4",
|
||||
"gulp-rev": "^10.0.0",
|
||||
"gulp-rev": "^11.0.0",
|
||||
"gulp-terser": "^2.1.0",
|
||||
"husky": "^9.1.6",
|
||||
"lint-staged": "^15.2.10",
|
||||
"npm-run-all2": "^6.2.6",
|
||||
"husky": "^9.1.7",
|
||||
"lint-staged": "^16.1.2",
|
||||
"npm-run-all2": "^8.0.4",
|
||||
"postcss": "^8.5.6",
|
||||
"postcss-cli": "^11.0.0",
|
||||
"postcss-import": "^16.1.0",
|
||||
"prettier": "^3.3.3",
|
||||
"prettier-plugin-tailwindcss": "^0.6.8",
|
||||
"stylelint": "^16.10.0",
|
||||
"stylelint-config-standard": "^36.0.1",
|
||||
"postcss-cli": "^11.0.1",
|
||||
"postcss-import": "^16.1.1",
|
||||
"prettier": "^3.5.3",
|
||||
"prettier-plugin-tailwindcss": "^0.6.12",
|
||||
"stylelint": "^16.20.0",
|
||||
"stylelint-config-standard": "^38.0.0",
|
||||
"tailwindcss": "^3.4.14",
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
},
|
||||
|
||||
Generated
+432
-447
File diff suppressed because it is too large.
Load diff
@@ -137,12 +137,15 @@ Roleplay
|
||||
[verb] [task] [specifics]
|
||||
|
||||
#### 5W1H Questions
|
||||
|
||||
Who
|
||||
|
||||
- Who is X?
|
||||
- Who is [involved | affected | responsible] for X?
|
||||
- Who should I contact for help with X?
|
||||
|
||||
What
|
||||
|
||||
- [What is | define | explain | describe] X?
|
||||
- What does X do?
|
||||
- What did [entity | text] mean by [quote]?
|
||||
@@ -154,15 +157,18 @@ What
|
||||
- What are the top 5 X?
|
||||
|
||||
When
|
||||
|
||||
- When [did | will] [entity | event] occur?
|
||||
- When is X due?
|
||||
- When is the best time to initiate X?
|
||||
|
||||
Where
|
||||
|
||||
- Where did [entity | event] happen?
|
||||
- [Where to find X? | where to find resources about X? | suggest websites about X]
|
||||
|
||||
Why
|
||||
|
||||
- Why did [entity] choose [approach]?
|
||||
- Why [did | will] [event] occur?
|
||||
- Why is [approach] being implemented?
|
||||
@@ -171,30 +177,36 @@ Why
|
||||
- Why is it important?
|
||||
|
||||
How
|
||||
|
||||
- How to do X?
|
||||
- How does X work?
|
||||
- How does X do Y?
|
||||
- How to measure [metric] accurately?
|
||||
|
||||
#### Utility
|
||||
|
||||
Generate And Expand Content
|
||||
- Write [content type] to [entity] about [topic] should cover [aspects] ***(Content type examples: article, description, documentation, dummy data, email, resume, essay, guide, outline, program, recipe, SEO keywords, story, social media post, study plan, title, video script)***
|
||||
|
||||
- Write [content type] to [entity] about [topic] should cover [aspects] **_(Content type examples: article, description, documentation, dummy data, email, resume, essay, guide, outline, program, recipe, SEO keywords, story, social media post, study plan, title, video script)_**
|
||||
- Generate random [names | numbers | words | ideas | X] matching [criteria]
|
||||
- [Continue | expand]
|
||||
- Create image of X
|
||||
|
||||
Summarize And Outline
|
||||
|
||||
- [Summarise | write key takeaways | write main points | write main lesson | highlight important info]
|
||||
- [Shorten | write concise]
|
||||
- Create outline
|
||||
|
||||
Modify And Refine Text
|
||||
|
||||
- [Write better | improve]
|
||||
- Paraphrase
|
||||
- Correct spelling, grammar, punctuation errors
|
||||
- Change [narrative voice A] to [narrative voice B]
|
||||
|
||||
Explain And Teach
|
||||
|
||||
- [Explain | elaborate]
|
||||
- Explain [how to do | each step of] X
|
||||
- Explain what X does
|
||||
@@ -203,14 +215,17 @@ Explain And Teach
|
||||
- Provide [example | analogy]
|
||||
|
||||
Organize And Structure
|
||||
- Sort X by [key] in [order] ***(Sort order examples: alphabetical, chronological, ascending, descending, lexicographical, custom)***
|
||||
|
||||
- Sort X by [key] in [order] **_(Sort order examples: alphabetical, chronological, ascending, descending, lexicographical, custom)_**
|
||||
- Categorize
|
||||
|
||||
Plan And Strategize
|
||||
|
||||
- Plan [strategy for | goals and steps to achieve | milestones for | roadmap for] X
|
||||
- Create [schedule | timeline] for X
|
||||
|
||||
Recommend And Advise
|
||||
|
||||
- Recommend [media type] [on | similar to] [topic]
|
||||
- Recommend [gift ideas | thing] for [entity | occasion]
|
||||
- Recommend improvements
|
||||
@@ -218,15 +233,17 @@ Recommend And Advise
|
||||
- Give feedback on idea for X
|
||||
|
||||
Analyze And Compare
|
||||
|
||||
- Extract [themes | keywords | info] about X
|
||||
- Identify [similarities | differences] between X and Y
|
||||
- Analyse the [sentiment | tone] of X
|
||||
- Identify gaps in X
|
||||
- Evaluate [strengths and weaknesses | pros and cons] of X
|
||||
- Is X [comparison operator] Y? ***(Can be abstractly expressed as a sentence like "is an apple bigger than a walnut"?)***
|
||||
- Is X [comparison operator] Y? **_(Can be abstractly expressed as a sentence like "is an apple bigger than a walnut"?)_**
|
||||
- Reverse engineer X
|
||||
|
||||
Translate And Convert
|
||||
|
||||
- Translate [human language A] into [human language B]
|
||||
- Translate [programming language A] into [programming language B]
|
||||
- Translate into emojis
|
||||
@@ -234,25 +251,30 @@ Translate And Convert
|
||||
- Reformat as [output format]
|
||||
|
||||
Filter And Choose
|
||||
|
||||
- Filter X where [condition]
|
||||
- Exclude X where [condition]
|
||||
- Choose best from [options]
|
||||
- Choose [top | lowest | first | last | random] [quantity] from [options]
|
||||
|
||||
Real-Time Lookup And Verify
|
||||
|
||||
- Get up-to-date [facts | news | data] on X
|
||||
- Is this true?
|
||||
- Find [sources | references | citations] for X
|
||||
|
||||
Engagement And Trivia
|
||||
|
||||
- Give questions about X
|
||||
|
||||
Chat Memory
|
||||
|
||||
- What did you mean by X?
|
||||
- What was said earlier about X?
|
||||
- Use earlier context to do X
|
||||
|
||||
#### Conditional Clauses
|
||||
|
||||
- [Verb] [item number]
|
||||
- [Verb] the [first | last | random] [quantity] of X
|
||||
- [Verb] the [first | last | random] [quantity] of X where [condition]
|
||||
@@ -260,6 +282,7 @@ Chat Memory
|
||||
- [Verb] X where not [condition]
|
||||
|
||||
#### Database CRUD Operations
|
||||
|
||||
Create
|
||||
|
||||
- [Write content about X|suggest ideas about X|suggest titles about X]
|
||||
@@ -375,6 +398,7 @@ Presentation
|
||||
- Check list
|
||||
|
||||
Code
|
||||
|
||||
- Code
|
||||
|
||||
Process
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: FastAPI
|
||||
date: 2025-06-07 18:40:00
|
||||
background: bg-[#059669]
|
||||
title: FastAPI
|
||||
date: 2025-06-07 18:40:00
|
||||
background: bg-[#059669]
|
||||
tags:
|
||||
- web
|
||||
- python
|
||||
@@ -40,8 +40,6 @@ def root():
|
||||
uvicorn main:app --reload
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Routing & Parameters {.cols-3}
|
||||
|
||||
### Path Parameter
|
||||
@@ -68,8 +66,6 @@ def filter_data(limit: int = 10, active: bool = True):
|
||||
return {"limit": limit, "active": active}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Request Body & Validation {.cols-3}
|
||||
|
||||
### Using Pydantic
|
||||
@@ -98,8 +94,6 @@ def create(item: Item):
|
||||
return item
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Forms, Files, Headers {.cols-3}
|
||||
|
||||
### Form Input
|
||||
@@ -132,8 +126,6 @@ def info(ua: str = Header(None)):
|
||||
return {"UA": ua}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Middleware & Dependency {.cols-2}
|
||||
|
||||
### Middleware
|
||||
@@ -159,8 +151,6 @@ def secure(_: bool = Depends(auth)):
|
||||
return {"secure": True}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Errors & JSON API {.cols-2}
|
||||
|
||||
### HTTP Error
|
||||
@@ -183,8 +173,6 @@ def get_data():
|
||||
return {"status": "ok"}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Templates & Static {.cols-2}
|
||||
|
||||
### Mount Static
|
||||
@@ -201,8 +189,6 @@ from fastapi.templating import Jinja2Templates
|
||||
templates = Jinja2Templates("templates")
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Routers & Structure {.cols-2}
|
||||
|
||||
### Routers (Blueprints)
|
||||
@@ -230,14 +216,12 @@ project/
|
||||
└── models/
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Docs & Status {.cols-2}
|
||||
|
||||
### Built-in Docs
|
||||
|
||||
* Swagger: `/docs`
|
||||
* ReDoc: `/redoc`
|
||||
- Swagger: `/docs`
|
||||
- ReDoc: `/redoc`
|
||||
|
||||
### Custom Status Code
|
||||
|
||||
@@ -248,4 +232,3 @@ from fastapi import status
|
||||
def create():
|
||||
return {"msg": "Created"}
|
||||
```
|
||||
|
||||
+14
-28
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Flask
|
||||
date: 2025-06-07 19:05:00
|
||||
background: bg-[#3598db]
|
||||
title: Flask
|
||||
date: 2025-06-07 19:05:00
|
||||
background: bg-[#3598db]
|
||||
tags:
|
||||
- web
|
||||
- python
|
||||
@@ -42,8 +42,6 @@ export FLASK_APP=app.py
|
||||
flask run
|
||||
```
|
||||
|
||||
|
||||
|
||||
## App Config & Environment {.cols-3}
|
||||
|
||||
### App Object
|
||||
@@ -62,13 +60,11 @@ app.config.from_pyfile("config.py")
|
||||
|
||||
### Common Config Keys
|
||||
|
||||
| Key | Description |
|
||||
| | -- |
|
||||
| `DEBUG` | Enable debug mode |
|
||||
| Key | Description |
|
||||
| | -- |
|
||||
| `DEBUG` | Enable debug mode |
|
||||
| `SECRET_KEY` | For sessions/cookies |
|
||||
| `ENV` | Set to 'development' |
|
||||
|
||||
|
||||
| `ENV` | Set to 'development' |
|
||||
|
||||
## Routing & Methods {.cols-3}
|
||||
|
||||
@@ -96,8 +92,6 @@ def user(name):
|
||||
return f"User: {name}"
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Request & Response {.cols-3}
|
||||
|
||||
### Request Object
|
||||
@@ -112,9 +106,9 @@ def data():
|
||||
|
||||
### Request Attributes
|
||||
|
||||
* `request.args`: Query params
|
||||
* `request.form`: Form data
|
||||
* `request.json`: JSON body
|
||||
- `request.args`: Query params
|
||||
- `request.form`: Form data
|
||||
- `request.json`: JSON body
|
||||
|
||||
### Custom Response
|
||||
|
||||
@@ -128,8 +122,6 @@ def custom():
|
||||
return res
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Templates & Static {.cols-3}
|
||||
|
||||
### Render Template
|
||||
@@ -146,17 +138,17 @@ def page():
|
||||
|
||||
```html
|
||||
<h1>Hello {{ name }}</h1>
|
||||
{% if name %}<p>Hi!</p>{% endif %}
|
||||
{% if name %}
|
||||
<p>Hi!</p>
|
||||
{% endif %}
|
||||
```
|
||||
|
||||
### Static Files
|
||||
|
||||
```html
|
||||
<link href="{{ url_for('static', filename='style.css') }}">
|
||||
<link href="{{ url_for('static', filename='style.css') }}" />
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Sessions & Cookies {.cols-2}
|
||||
|
||||
### Using Sessions
|
||||
@@ -183,8 +175,6 @@ def cookie():
|
||||
return resp
|
||||
```
|
||||
|
||||
|
||||
|
||||
## JSON API & Middleware {.cols-2}
|
||||
|
||||
### JSON Response
|
||||
@@ -210,8 +200,6 @@ def after(res):
|
||||
return res
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Error Handling & Blueprints {.cols-2}
|
||||
|
||||
### Error Handling
|
||||
@@ -236,8 +224,6 @@ def dash():
|
||||
app.register_blueprint(admin)
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Project Structure {.cols-2}
|
||||
|
||||
### File Structure
|
||||
|
||||
+22
-59
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: HTMX
|
||||
date: 2025-06-07 19:30:00
|
||||
background: bg-[#ff5f4d]
|
||||
title: HTMX
|
||||
date: 2025-06-07 19:30:00
|
||||
background: bg-[#ff5f4d]
|
||||
tags:
|
||||
- frontend
|
||||
- javascript
|
||||
@@ -14,8 +14,6 @@ plugins:
|
||||
- copyCode
|
||||
---
|
||||
|
||||
|
||||
|
||||
## Getting Started {.cols-3}
|
||||
|
||||
### CDN Import
|
||||
@@ -27,11 +25,7 @@ plugins:
|
||||
### Basic Usage
|
||||
|
||||
```html
|
||||
<button
|
||||
hx-get="/hello"
|
||||
hx-target="#result">
|
||||
Say Hi
|
||||
</button>
|
||||
<button hx-get="/hello" hx-target="#result">Say Hi</button>
|
||||
<div id="result"></div>
|
||||
```
|
||||
|
||||
@@ -42,8 +36,6 @@ plugins:
|
||||
<p>Hello from server</p>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Core Attributes {.cols-3}
|
||||
|
||||
### `hx-get`, `hx-post`, etc.
|
||||
@@ -63,28 +55,24 @@ plugins:
|
||||
### `hx-trigger`
|
||||
|
||||
```html
|
||||
<input
|
||||
hx-get="/search"
|
||||
<input
|
||||
hx-get="/search"
|
||||
hx-trigger="keyup changed delay:300ms"
|
||||
hx-target="#results" />
|
||||
hx-target="#results"
|
||||
/>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Swap & Out of Band {.cols-3}
|
||||
|
||||
### `hx-swap`
|
||||
|
||||
```html
|
||||
<div
|
||||
hx-get="/frag"
|
||||
hx-swap="innerHTML">
|
||||
</div>
|
||||
<div hx-get="/frag" hx-swap="innerHTML"></div>
|
||||
```
|
||||
|
||||
* `outerHTML`
|
||||
* `innerHTML`
|
||||
* `beforebegin`, `afterbegin`, etc.
|
||||
- `outerHTML`
|
||||
- `innerHTML`
|
||||
- `beforebegin`, `afterbegin`, etc.
|
||||
|
||||
### `hx-swap-oob`
|
||||
|
||||
@@ -92,7 +80,7 @@ plugins:
|
||||
<div hx-swap-oob="true" id="msg"></div>
|
||||
```
|
||||
|
||||
*Useful for global updates from partials.*
|
||||
_Useful for global updates from partials._
|
||||
|
||||
### Swap Modifiers
|
||||
|
||||
@@ -100,8 +88,6 @@ plugins:
|
||||
hx-swap="outerHTML transition:true swap:1s"
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Forms & Events {.cols-3}
|
||||
|
||||
### Auto POST on Submit
|
||||
@@ -118,35 +104,21 @@ hx-swap="outerHTML transition:true swap:1s"
|
||||
|
||||
```html
|
||||
<input id="user-id" name="id" />
|
||||
<button
|
||||
hx-post="/update"
|
||||
hx-include="#user-id">
|
||||
Update
|
||||
</button>
|
||||
<button hx-post="/update" hx-include="#user-id">Update</button>
|
||||
```
|
||||
|
||||
### `hx-vals`
|
||||
|
||||
```html
|
||||
<button
|
||||
hx-post="/save"
|
||||
hx-vals='{"id": 42, "active": true}'>
|
||||
Save
|
||||
</button>
|
||||
<button hx-post="/save" hx-vals='{"id": 42, "active": true}'>Save</button>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Advanced Features {.cols-3}
|
||||
|
||||
### Loading Indicator
|
||||
|
||||
```html
|
||||
<button
|
||||
hx-get="/load"
|
||||
hx-indicator="#spinner">
|
||||
Load
|
||||
</button>
|
||||
<button hx-get="/load" hx-indicator="#spinner">Load</button>
|
||||
<div id="spinner" class="htmx-indicator">Loading...</div>
|
||||
```
|
||||
|
||||
@@ -162,23 +134,21 @@ hx-swap="outerHTML transition:true swap:1s"
|
||||
<div hx-get="/time" hx-trigger="every 5s"></div>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Events & Extensions {.cols-3}
|
||||
|
||||
### Listen to Events
|
||||
|
||||
```js
|
||||
document.body.addEventListener('htmx:afterSwap', e => {
|
||||
console.log("Swap complete");
|
||||
document.body.addEventListener('htmx:afterSwap', (e) => {
|
||||
console.log('Swap complete');
|
||||
});
|
||||
```
|
||||
|
||||
### Event Hooks
|
||||
|
||||
* `htmx:beforeRequest`
|
||||
* `htmx:afterSwap`
|
||||
* `htmx:responseError`
|
||||
- `htmx:beforeRequest`
|
||||
- `htmx:afterSwap`
|
||||
- `htmx:responseError`
|
||||
|
||||
### Extensions
|
||||
|
||||
@@ -187,8 +157,6 @@ document.body.addEventListener('htmx:afterSwap', e => {
|
||||
<form hx-post="/api" hx-ext="json-enc"></form>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Example Use Case {.cols-2}
|
||||
|
||||
### Python Backend (Flask)
|
||||
@@ -202,11 +170,6 @@ def hello():
|
||||
### HTML Client
|
||||
|
||||
```html
|
||||
<button
|
||||
hx-get="/hello"
|
||||
hx-target="#msg">
|
||||
Click
|
||||
</button>
|
||||
<button hx-get="/hello" hx-target="#msg">Click</button>
|
||||
<div id="msg"></div>
|
||||
```
|
||||
|
||||
+14
-16
@@ -1,13 +1,13 @@
|
||||
---
|
||||
title: "Matplotlib"
|
||||
title: 'Matplotlib'
|
||||
date: 06-06-2025
|
||||
background: bg-[#1a073e]
|
||||
tags:
|
||||
- "data visualization"
|
||||
- "matplotlib"
|
||||
- "plotting"
|
||||
- 'data visualization'
|
||||
- 'matplotlib'
|
||||
- 'plotting'
|
||||
categories:
|
||||
- "Python"
|
||||
- 'Python'
|
||||
intro: |
|
||||
[Matplotlib](https://matplotlib.org/) is a comprehensive library for creating static, animated, and interactive plots in Python.
|
||||
This cheat sheet provides a quick reference from basic to advanced usage, covering essential features for data science, machine learning, and scientific computing.
|
||||
@@ -15,10 +15,9 @@ plugins:
|
||||
- copyCode
|
||||
---
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Getting Started {.cols-2}
|
||||
## Getting Started {.cols-2}
|
||||
|
||||
### Importing
|
||||
|
||||
@@ -38,7 +37,7 @@ plt.show() # Display the plot
|
||||
|
||||
---
|
||||
|
||||
## Plot Types {.cols-2}
|
||||
## Plot Types {.cols-2}
|
||||
|
||||
### Line Plot
|
||||
|
||||
@@ -98,7 +97,7 @@ plt.show()
|
||||
|
||||
---
|
||||
|
||||
## Customization {.row-span-2}
|
||||
## Customization {.row-span-2}
|
||||
|
||||
| Feature | Code Example | Description |
|
||||
| --------------- | ------------------------------------------------------------------------------------ | ------------------------------------------- |
|
||||
@@ -117,7 +116,7 @@ plt.show()
|
||||
|
||||
---
|
||||
|
||||
## Subplots & Layouts
|
||||
## Subplots & Layouts
|
||||
|
||||
### Multiple Subplots
|
||||
|
||||
@@ -139,7 +138,7 @@ plt.figure(figsize=(10, 5)) # Set figure size (width, height in inches)
|
||||
|
||||
---
|
||||
|
||||
## Advanced Visualizations {.cols-2}
|
||||
## Advanced Visualizations {.cols-2}
|
||||
|
||||
### Heatmap
|
||||
|
||||
@@ -174,7 +173,7 @@ plt.show()
|
||||
|
||||
---
|
||||
|
||||
## Working with Images
|
||||
## Working with Images
|
||||
|
||||
```python
|
||||
import matplotlib.image as mpimg
|
||||
@@ -233,7 +232,7 @@ plt.show()
|
||||
|
||||
---
|
||||
|
||||
## Saving Plots
|
||||
## Saving Plots
|
||||
|
||||
```python
|
||||
plt.savefig("figure.png", dpi=300, bbox_inches='tight') # Save plot to file
|
||||
@@ -241,7 +240,7 @@ plt.savefig("figure.png", dpi=300, bbox_inches='tight') # Save plot to file
|
||||
|
||||
---
|
||||
|
||||
## Show & Clear
|
||||
## Show & Clear
|
||||
|
||||
```python
|
||||
plt.show() # Show plot window
|
||||
@@ -251,7 +250,7 @@ plt.close() # Close figure window (useful in scripts or GUI apps)
|
||||
|
||||
---
|
||||
|
||||
## More Useful Functions
|
||||
## More Useful Functions
|
||||
|
||||
| Function | Use Case |
|
||||
| ------------------------------ | ------------------------------- |
|
||||
@@ -265,4 +264,3 @@ plt.close() # Close figure window (useful in scripts or GUI apps)
|
||||
| `plt.gcf()` | Get current figure |
|
||||
|
||||
---
|
||||
|
||||
+20
-29
@@ -957,8 +957,9 @@ else:
|
||||
|
||||
Also see: [Python Tips](https://book.pythontips.com/en/latest/for_-_else.html)
|
||||
|
||||
### Over Dictionary
|
||||
````python
|
||||
### Over Dictionary
|
||||
|
||||
```python
|
||||
johndict = {
|
||||
"firstname": "John",
|
||||
"lastname": "Doe",
|
||||
@@ -968,18 +969,17 @@ johndict = {
|
||||
x = johndict.items()
|
||||
print(x)
|
||||
|
||||
# Output: dict_items([('firstname', 'John'),
|
||||
# Output: dict_items([('firstname', 'John'),
|
||||
# ('lastname', 'Doe'),
|
||||
# ('age', 30)])
|
||||
|
||||
for key, value in johndict.items():
|
||||
print(f"{key} : : {value}")
|
||||
print(f"{key} : : {value}")
|
||||
|
||||
# Output: firstname : : John
|
||||
# Output: lastname : : Doe
|
||||
# Output: age : : 30
|
||||
````
|
||||
|
||||
```
|
||||
|
||||
## Python Comprehensions
|
||||
|
||||
@@ -993,7 +993,7 @@ newlist = [x for x in languages if "l" not in x]
|
||||
|
||||
print(newlist) #Output : [ 'go', 'rust', 'javascript', 'python']
|
||||
|
||||
# List comprehension avoid this :
|
||||
# List comprehension avoid this :
|
||||
oldlist = []
|
||||
for x in languages:
|
||||
if "l" not in x:
|
||||
@@ -1016,10 +1016,10 @@ print(language_dict)
|
||||
# 'javascript': True, 'python': True}
|
||||
|
||||
|
||||
# Dictionary comprehension avoid this :
|
||||
# Dictionary comprehension avoid this :
|
||||
|
||||
language_dict2 = {}
|
||||
|
||||
|
||||
for e in languages:
|
||||
if "l" not in e:
|
||||
language_dict2[e] = True
|
||||
@@ -1031,8 +1031,6 @@ print(language_dict2)
|
||||
# 'javascript': True, 'python': True}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Python Functions
|
||||
|
||||
### Basic
|
||||
@@ -1105,6 +1103,7 @@ add(5, 20) # => 25
|
||||
# => 5
|
||||
(lambda x, y: x ** 2 + y ** 2)(2, 1)
|
||||
```
|
||||
|
||||
### @decorator {.col-span-2}
|
||||
|
||||
```python
|
||||
@@ -1120,13 +1119,14 @@ def handle_errors(func):
|
||||
return print(f"Error : {e}")
|
||||
return wrapper
|
||||
|
||||
# Decorate function or method
|
||||
# Decorate function or method
|
||||
@handle_errors
|
||||
def divide(a, b):
|
||||
return a / b
|
||||
|
||||
divide(10, 0) # Output : Error : division by zero
|
||||
```
|
||||
|
||||
## Python Modules
|
||||
|
||||
### Import modules
|
||||
@@ -1395,8 +1395,7 @@ print(Yoki.legs) # => 4
|
||||
Yoki.sound() # => Woof!
|
||||
```
|
||||
|
||||
|
||||
### @staticmethod {.col-span-2}
|
||||
### @staticmethod {.col-span-2}
|
||||
|
||||
```python
|
||||
class MyClass:
|
||||
@@ -1640,24 +1639,20 @@ while (data := values[i]):
|
||||
|
||||
# Expected result: 1, "text", True
|
||||
```
|
||||
## Date & Time Handling
|
||||
|
||||
## Date & Time Handling
|
||||
|
||||
### Current date and time
|
||||
|
||||
|
||||
```python
|
||||
import datetime
|
||||
|
||||
now = datetime.datetime.now()
|
||||
print(now) # e.g., 2024-04-27 14:35:22.123456
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Creating specific date/time objects
|
||||
### Creating specific date/time objects
|
||||
|
||||
|
||||
```python
|
||||
import datetime
|
||||
|
||||
@@ -1673,11 +1668,9 @@ print(t) # 15:30:45
|
||||
dt = datetime.datetime(2024, 4, 27, 15, 30, 45)
|
||||
print(dt) # 2024-04-27 15:30:45
|
||||
```
|
||||
|
||||
|
||||
### Converting between date formats
|
||||
### Converting between date formats
|
||||
|
||||
|
||||
```python
|
||||
import datetime
|
||||
|
||||
@@ -1690,11 +1683,10 @@ print(dt_obj) # 2024-04-27 14:00:00
|
||||
formatted_str = dt_obj.strftime("%d/%m/%Y %H:%M")
|
||||
print(formatted_str) # 27/04/2024 14:00
|
||||
```
|
||||
|
||||
|
||||
### Timestamps and Unix time
|
||||
|
||||
```python
|
||||
```python
|
||||
import datetime
|
||||
|
||||
# Get current timestamp
|
||||
@@ -1704,11 +1696,11 @@ print(timestamp) # e.g., 1714188922.123456
|
||||
# Convert timestamp back to datetime
|
||||
dt_from_timestamp = datetime.datetime.fromtimestamp(timestamp)
|
||||
print(dt_from_timestamp)
|
||||
```
|
||||
```
|
||||
|
||||
### Date difference and timedelta {.col-span-2}
|
||||
|
||||
```python
|
||||
```python
|
||||
import datetime
|
||||
|
||||
date1 = datetime.date(2024, 4, 27)
|
||||
@@ -1722,7 +1714,6 @@ new_date = date1 + datetime.timedelta(days=10)
|
||||
print(new_date) # 2024-05-07
|
||||
```
|
||||
|
||||
|
||||
## Miscellaneous
|
||||
|
||||
### Comments
|
||||
@@ -1781,7 +1772,7 @@ finally: # Execute under all circumstances
|
||||
print("We can clean up resources here")
|
||||
```
|
||||
|
||||
### Dispatcher Pattern {.col-span-3}
|
||||
### Dispatcher Pattern {.col-span-3}
|
||||
|
||||
```python
|
||||
# Dispatcher allows dynamic selection and execution of functions based on user input or other runtime conditions
|
||||
|
||||
+13
-14
@@ -249,26 +249,25 @@ $ ssh-keygen -R <ip/hostname>
|
||||
- PEM
|
||||
- PKCS8
|
||||
|
||||
|
||||
|
||||
## SSH Tunneling
|
||||
## SSH Tunneling
|
||||
|
||||
### SSH Tunnel Options {.row-span-2}
|
||||
|
||||
| Option | Description |
|
||||
|--------|:--------------------------------------------------------|
|
||||
| `-L` | Local port forwarding |
|
||||
| `-R` | Remote port forwarding |
|
||||
| `-D` | Dynamic port forwarding |
|
||||
| `-f` | Run in background |
|
||||
| `-N` | Do not execute a remote command |
|
||||
| `-g` | Allow remote hosts to connect to local forwarded ports |
|
||||
| Option | Description |
|
||||
| ------ | :----------------------------------------------------- |
|
||||
| `-L` | Local port forwarding |
|
||||
| `-R` | Remote port forwarding |
|
||||
| `-D` | Dynamic port forwarding |
|
||||
| `-f` | Run in background |
|
||||
| `-N` | Do not execute a remote command |
|
||||
| `-g` | Allow remote hosts to connect to local forwarded ports |
|
||||
|
||||
{.left-text}
|
||||
|
||||
more details on flag above with `man ssh`
|
||||
|
||||
### Local Port Forwarding {.col-span-2}
|
||||
### Local Port Forwarding {.col-span-2}
|
||||
|
||||
```bash
|
||||
# Forward a local port to a remote server
|
||||
ssh -L local_port:remote_host:remote_port user@ssh_server
|
||||
@@ -288,6 +287,7 @@ ssh -f -N -D 1080 user@ssh_server
|
||||
```
|
||||
|
||||
### Background Tunnel {.col-span-3}
|
||||
|
||||
```bash
|
||||
# Create a local port forwarding tunnel in the background
|
||||
ssh -f -N -L local_port:remote_host:remote_port user@ssh_server
|
||||
@@ -305,8 +305,7 @@ ssh -L 8080:example.com:80 -L 3306:db.example.com:3306 user@ssh_server
|
||||
```bash
|
||||
# In background, no command, allow remote host, local port forward, identity_file
|
||||
ssh -f -N -g -L 8080:example.com:80 -i ~/.ssh/custom_key user@ssh_server
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
## Also see
|
||||
|
||||
|
||||
+2
-14
@@ -7,7 +7,7 @@ const STATIC_ASSETS = [
|
||||
'/',
|
||||
'/css/style.css',
|
||||
'/js/main.js',
|
||||
'/js/fuse_6.4.6.js',
|
||||
'/js/fuse_7.1.0.js',
|
||||
'/manifest.json',
|
||||
'/search.json'
|
||||
];
|
||||
@@ -24,24 +24,20 @@ const CACHE_PATTERNS = [
|
||||
|
||||
// Service Worker installevent
|
||||
self.addEventListener('install', (event) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Service Worker: Installing...');
|
||||
|
||||
event.waitUntil(
|
||||
caches
|
||||
.open(STATIC_CACHE)
|
||||
.then((cache) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Service Worker: Caching static assets');
|
||||
return cache.addAll(STATIC_ASSETS);
|
||||
})
|
||||
.then(() => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Service Worker: Static assets cached');
|
||||
return self.skipWaiting();
|
||||
})
|
||||
.catch((error) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Service Worker: Cache failed', error);
|
||||
})
|
||||
);
|
||||
@@ -49,7 +45,6 @@ self.addEventListener('install', (event) => {
|
||||
|
||||
// Service Worker activate event
|
||||
self.addEventListener('activate', (event) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Service Worker: Activating...');
|
||||
|
||||
event.waitUntil(
|
||||
@@ -60,7 +55,6 @@ self.addEventListener('activate', (event) => {
|
||||
cacheNames.map((cacheName) => {
|
||||
// Delete old cache versions
|
||||
if (cacheName !== STATIC_CACHE && cacheName !== DYNAMIC_CACHE) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Service Worker: Deleting old cache', cacheName);
|
||||
return caches.delete(cacheName);
|
||||
}
|
||||
@@ -68,7 +62,6 @@ self.addEventListener('activate', (event) => {
|
||||
);
|
||||
})
|
||||
.then(() => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Service Worker: Activated');
|
||||
return self.clients.claim();
|
||||
})
|
||||
@@ -124,7 +117,6 @@ async function handleCacheRequest(request) {
|
||||
// 6. Nothing available, return offline page
|
||||
return createOfflineResponse(url.pathname);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Service Worker: Fetch failed', error);
|
||||
|
||||
// Network error, try to return cache
|
||||
@@ -250,7 +242,6 @@ async function doBackgroundSync() {
|
||||
cache.put('/search.json', response);
|
||||
}
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Background sync failed:', error);
|
||||
}
|
||||
}
|
||||
@@ -291,9 +282,6 @@ self.addEventListener('notificationclick', (event) => {
|
||||
event.notification.close();
|
||||
|
||||
if (event.action === 'explore') {
|
||||
event.waitUntil(
|
||||
// eslint-disable-next-line no-undef
|
||||
clients.openWindow('/')
|
||||
);
|
||||
event.waitUntil(clients.openWindow('/'));
|
||||
}
|
||||
});
|
||||
@@ -1,40 +1,104 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Create a safe highlight.js wrapper
|
||||
const hljs = require('highlight.js');
|
||||
|
||||
// Create a custom highlight function
|
||||
const customHighlight = function (str, lang) {
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
try {
|
||||
return hljs.highlight(str, { language: lang, ignoreIllegals: true }).value;
|
||||
} catch (err) {
|
||||
console.warn(`Highlight.js error for language "${lang}":`, err.message);
|
||||
}
|
||||
// Helper function to safely require plugins that might be ES modules
|
||||
function safeRequire(moduleName) {
|
||||
const plugin = require(moduleName);
|
||||
let result = plugin.default || plugin;
|
||||
|
||||
// Special handling for markdown-it-emoji v3.0.0+ which exports an object with multiple functions
|
||||
if (moduleName === 'markdown-it-emoji' && typeof result === 'object' && result.full) {
|
||||
result = result.full; // Use the full emoji plugin
|
||||
}
|
||||
// If the language is not supported, return an empty string, let markdown-it use the default processor
|
||||
return '';
|
||||
|
||||
// Special handling for other ES modules with default export
|
||||
if (typeof result === 'object' && result.default && typeof result.default === 'function') {
|
||||
result = result.default;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Create a custom highlight.js instance that handles unknown languages gracefully
|
||||
const customHljs = {
|
||||
highlight: function (code, options) {
|
||||
const language = options && options.language ? options.language : '';
|
||||
|
||||
// If no language specified, try auto-detection
|
||||
if (!language) {
|
||||
try {
|
||||
return hljs.highlightAuto(code);
|
||||
} catch {
|
||||
return {
|
||||
value: hljs.util.escapeHTML(code),
|
||||
language: 'plaintext',
|
||||
relevance: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the language is supported
|
||||
if (hljs.getLanguage(language)) {
|
||||
try {
|
||||
return hljs.highlight(code, {
|
||||
language: language,
|
||||
ignoreIllegals: true
|
||||
});
|
||||
} catch {
|
||||
// If highlighting fails, fall back to plain text without warning
|
||||
return {
|
||||
value: hljs.util.escapeHTML(code),
|
||||
language: 'plaintext',
|
||||
relevance: 0
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// Language not supported, try auto-detection or fall back to plain text
|
||||
try {
|
||||
const autoResult = hljs.highlightAuto(code);
|
||||
// Only use auto-detection if confidence is reasonable
|
||||
if (autoResult.relevance > 3) {
|
||||
return autoResult;
|
||||
}
|
||||
} catch {
|
||||
// Auto-detection failed, ignore
|
||||
}
|
||||
|
||||
// Fall back to plain text without warning
|
||||
return {
|
||||
value: hljs.util.escapeHTML(code),
|
||||
language: 'plaintext',
|
||||
relevance: 0
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
// Expose other hljs methods that might be needed
|
||||
getLanguage: hljs.getLanguage.bind(hljs),
|
||||
listLanguages: hljs.listLanguages.bind(hljs),
|
||||
util: hljs.util
|
||||
};
|
||||
|
||||
hexo.extend.filter.register('markdown-it:renderer', (md) => {
|
||||
md.use(require('markdown-it-abbr'), {});
|
||||
md.use(require('markdown-it-footnote'), {});
|
||||
md.use(require('markdown-it-ins'), {});
|
||||
md.use(require('markdown-it-sub'), {});
|
||||
md.use(require('markdown-it-sup'), {});
|
||||
md.use(require('markdown-it-task-lists'), {});
|
||||
md.use(require('markdown-it-emoji'), {});
|
||||
md.use(require('markdown-it-attrs'), {});
|
||||
md.use(require('markdown-it-highlightjs'), {
|
||||
hljs: {
|
||||
highlight: customHighlight
|
||||
}
|
||||
md.use(safeRequire('markdown-it-abbr'), {});
|
||||
md.use(safeRequire('markdown-it-footnote'), {});
|
||||
md.use(safeRequire('markdown-it-ins'), {});
|
||||
md.use(safeRequire('markdown-it-sub'), {});
|
||||
md.use(safeRequire('markdown-it-sup'), {});
|
||||
md.use(safeRequire('markdown-it-task-lists'), {});
|
||||
md.use(safeRequire('markdown-it-emoji'), {});
|
||||
md.use(safeRequire('markdown-it-attrs'), {});
|
||||
md.use(safeRequire('markdown-it-highlightjs'), {
|
||||
hljs: customHljs,
|
||||
auto: true,
|
||||
code: true,
|
||||
ignoreIllegals: true
|
||||
});
|
||||
md.use(require('markdown-it-checkbox'), {});
|
||||
md.use(require('markdown-it-shortcode-tag'), {
|
||||
md.use(safeRequire('markdown-it-checkbox'), {});
|
||||
md.use(safeRequire('markdown-it-shortcode-tag'), {
|
||||
widget: {
|
||||
render(attrs, _env) {
|
||||
render(attrs) {
|
||||
const widgetPath = path.resolve(`./source/widget/${attrs.name}.html`);
|
||||
if (fs.existsSync(widgetPath)) {
|
||||
return fs.readFileSync(widgetPath, 'utf8').trim();
|
||||
@@ -63,6 +127,12 @@ hexo.extend.filter.register('markdown-it:renderer', (md) => {
|
||||
function headerSections(md, options) {
|
||||
const opts = Object.assign({}, options);
|
||||
|
||||
// Check if the rule has already been added to prevent duplicate rules
|
||||
// This is crucial for hexo-renderer-markdown-it v6.0.0+ where the md instance is reused
|
||||
if (md.core.ruler.__rules__.some((rule) => rule.name === 'header_sections')) {
|
||||
return;
|
||||
}
|
||||
|
||||
function addSections(state) {
|
||||
const tokens = []; // output
|
||||
const Token = state.Token;
|
||||
@@ -164,7 +234,7 @@ function headerSections(md, options) {
|
||||
attrs = [];
|
||||
}
|
||||
let appended = false;
|
||||
attrs.forEach((x, _i) => {
|
||||
attrs.forEach((x) => {
|
||||
if (x[0] === 'class') {
|
||||
x[1] = `${cls} ${x[1]}`;
|
||||
appended = true;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
/**
|
||||
* Fuse.js v6.4.6 - Lightweight fuzzy-search (http://fusejs.io)
|
||||
*
|
||||
* Copyright (c) 2021 Kiro Risk (http://kiro.me)
|
||||
* All Rights Reserved. Apache Software License 2.0
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
var e,t;e=this,t=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function c(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&u(e,t)}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function f(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=s(e);if(t){var i=s(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return h(this,n)}}function l(e){return function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function v(e){return Array.isArray?Array.isArray(e):"[object Array]"===b(e)}function g(e){return"string"==typeof e}function y(e){return"number"==typeof e}function p(e){return!0===e||!1===e||function(e){return m(e)&&null!==e}(e)&&"[object Boolean]"==b(e)}function m(t){return"object"===e(t)}function k(e){return null!=e}function M(e){return!e.trim().length}function b(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}var x=function(e){return"Invalid value for key ".concat(e)},L=function(e){return"Pattern length exceeds max of ".concat(e,".")},S=Object.prototype.hasOwnProperty,w=function(){function e(n){var r=this;t(this,e),this._keys=[],this._keyMap={};var i=0;n.forEach((function(e){var t=_(e);i+=t.weight,r._keys.push(t),r._keyMap[t.id]=t,i+=t.weight})),this._keys.forEach((function(e){e.weight/=i}))}return r(e,[{key:"get",value:function(e){return this._keyMap[e]}},{key:"keys",value:function(){return this._keys}},{key:"toJSON",value:function(){return JSON.stringify(this._keys)}}]),e}();function _(e){var t=null,n=null,r=null,i=1;if(g(e)||v(e))r=e,t=O(e),n=j(e);else{if(!S.call(e,"name"))throw new Error(function(e){return"Missing ".concat(e," property in key")}("name"));var o=e.name;if(r=o,S.call(e,"weight")&&(i=e.weight)<=0)throw new Error(function(e){return"Property 'weight' in key '".concat(e,"' must be a positive integer")}(o));t=O(o),n=j(o)}return{path:t,id:n,weight:i,src:r}}function O(e){return v(e)?e:e.split(".")}function j(e){return v(e)?e.join("."):e}var A=c({},{isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:function(e,t){return e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1}},{},{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},{},{location:0,threshold:.6,distance:100},{},{useExtendedSearch:!1,getFn:function(e,t){var n=[],r=!1;return function e(t,i,o){if(k(t))if(i[o]){var c=t[i[o]];if(!k(c))return;if(o===Line truncated
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Fuse.js v7.1.0 - Lightweight fuzzy-search (http://fusejs.io)
|
||||
*
|
||||
* Copyright (c) 2025 Kiro Risk (http://kiro.me)
|
||||
* All Rights Reserved. Apache Software License 2.0
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
var e,t;e=this,t=function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?e(Object(r),!0).forEach((function(e){o(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,v(r.key),r)}}function u(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(e,t,n){return(t=v(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&s(e,t)}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function h(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function l(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=a(e);if(t){var i=a(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return h(this,n)}}function f(e){return function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function v(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}function g(e){return Array.isArray?Array.isArray(e):"[object Array]"===M(e)}var y=1/0;function p(e){return null==e?"":function(e){if("string"==typeof e)return e;var t=e+"";return"0"==t&&1/e==-y?"-0":t}(e)}function A(e){return"string"==typeof e}function m(e){return"number"==typeof e}function C(e){return!0===e||!1===e||function(e){return k(e)&&null!==e}(e)&&"[object Boolean]"==M(e)}function k(e){return"object"===n(e)}function E(e){return null!=e}function F(e){return!e.trim().length}function M(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}var b=function(e){return"Missing ".concat(e," property in key")},D=function(e){return"Property 'weight' in key '".concat(e,"' must be a positive integer")},B=Object.prototype.hasOwnProperty,x=function(){function e(t){var n=this;r(this,e),this._keys=[],this._keyMap={};var i=0;t.forEach((function(e){var t=w(e);n._keys.push(t),n._keyMap[t.id]=t,i+=t.weight})),this._keys.forEach((function(e){e.weight/=i}))}return u(e,[{key:"get",value:function(e){return this._keyMap[e]}},{key:"keys",value:function(){return this._keys}},{key:"toJSON",value:function(){return JSON.stringify(this._keys)}}]),e}();function w(e){var t=null,n=null,r=null,i=1,u=null;if(A(e)||g(e))r=e,t=S(e),n=L(e);else{if(!B.call(e,"name"))throw new ErLine truncated
|
||||
@@ -2,7 +2,7 @@ const Utils = (function () {
|
||||
return {
|
||||
LIBRARY: {
|
||||
fuse: {
|
||||
lib: ['/js/fuse_6.4.6.js'],
|
||||
lib: ['/js/fuse_7.1.0.js'],
|
||||
instance: 'Fuse',
|
||||
attr: { async: true }
|
||||
}
|
||||
@@ -488,14 +488,12 @@ window.addEventListener('load', () => {
|
||||
Utils.externalLibrary(Utils.LIBRARY.fuse)
|
||||
.then((Fuse) => {
|
||||
if (typeof Fuse === 'undefined') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Fuse.js library failed to load');
|
||||
return;
|
||||
}
|
||||
new SearchEngine().start();
|
||||
})
|
||||
.catch((error) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Failed to load search library:', error);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user