Skip to content

Commit

Permalink
vault backup: 2024-05-01 10:15:15
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed May 1, 2024
1 parent fc9c9a5 commit 1dc2ba8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
10 changes: 5 additions & 5 deletions content/zh-cn/post/go-pc-control-model/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ tags:
但在这样一个功能的基础上,`Context` 还提供了一些特殊字段和控制方法,用来实现对协程的控制。
最重要的一种用法如下:

``` Golang
```go
select {
case <-ctx.Done():
case <- ctx.Done():
return
default:
// normal works when this goroutine is up
Expand All @@ -88,7 +88,7 @@ default:

我们首先定义消息的格式,并准备 `channel``Context`

``` Golang
```go
type Message struct {
Content string
}
Expand All @@ -108,7 +108,7 @@ func main() {
### Producer 核心逻辑
``` Golang
```go
select {
// Handle <-ctx.Done()
case <-ctx.Done():
Expand All @@ -130,7 +130,7 @@ default:
### Consumer 核心逻辑
``` Golang
```go
// Consume
data := <-dataCh
fmt.Printf("Consumer_%d get message: %s\n", id, data.Content)
Expand Down
55 changes: 55 additions & 0 deletions scripts/create-post.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
param (
[string]$slug,
[string]$language = "zh-cn"
)

if ([string]::IsNullOrEmpty($slug)) {
Write-Host "Please provide a slug for the post"
exit
}

$post_dir = "content/$language/post/$slug"
$post_md = "$post_dir/index.md"

if (Test-Path $post_md) {
Write-Host "Post already exists at $post_md"
$old_date = Select-String -Path $post_md -Pattern "^date:" | % { $_.Line -replace "^date: *", "" }
Write-Host "Old post date is $old_date"
$update = Read-Host "Do you want to update the post date? [Y/n]"
if ($update -ne "Y") {
Write-Host "Nothing to be done, exiting"
exit
}
$new_date = Get-Date -Format "yyyy-MM-dd HH:mm:sszzz"
$new_date = $new_date -replace ":(?=\d{2}$)", ""
(Get-Content $post_md) | ForEach-Object { $_ -replace "^date:.*$", "date: $new_date" } | Set-Content $post_md
Write-Host "Post date updated to $new_date"
exit
}

Write-Host "Creating post at $post_md"
$create = Read-Host "Do you want to create a new post with the slug $slug? [Y/n]"
if ($create -ne "Y") {
Write-Host "Nothing to be done, exiting"
exit
}

New-Item -ItemType Directory -Force -Path $post_dir
New-Item -ItemType File -Force -Path $post_md
$date = Get-Date -Format "yyyy-MM-dd HH:mm:sszzz"
$date = $date -replace ":(?=\d{2}$)", ""
@"
---
title:
description:
slug: $slug
date: $date
image:
categories:
-
tags:
-
---
"@ | Set-Content $post_md

Write-Host "Post created at $post_md"

0 comments on commit 1dc2ba8

Please sign in to comment.