From 4a89ca30943b7ed0bd56727de129265550321022 Mon Sep 17 00:00:00 2001 From: amwps290 Date: Wed, 3 Feb 2021 10:05:22 +0800 Subject: [PATCH 01/18] Delete 20210126 Write GIMP scripts to make image processing faster.md --- ...scripts to make image processing faster.md | 271 ------------------ 1 file changed, 271 deletions(-) delete mode 100644 sources/tech/20210126 Write GIMP scripts to make image processing faster.md diff --git a/sources/tech/20210126 Write GIMP scripts to make image processing faster.md b/sources/tech/20210126 Write GIMP scripts to make image processing faster.md deleted file mode 100644 index ffe60e8538..0000000000 --- a/sources/tech/20210126 Write GIMP scripts to make image processing faster.md +++ /dev/null @@ -1,271 +0,0 @@ -[#]: collector: (lujun9972) -[#]: translator: (amwps290) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) -[#]: subject: (Write GIMP scripts to make image processing faster) -[#]: via: (https://opensource.com/article/21/1/gimp-scripting) -[#]: author: (Cristiano L. Fontana https://opensource.com/users/cristianofontana) - -Write GIMP scripts to make image processing faster -====== -Learn GIMP's scripting language Script-Fu by adding an effect to a batch -of images. -![Painting art on a computer screen][1] - -Some time ago, I wanted to give a blackboard-style look to a typeset equation. I started playing around with the [GNU Image Manipulation Program (GIMP)][2] and was satisfied with the result. The problem was that I had to perform several actions on the image, I wanted to use this style again, and I did not want to repeat the steps for all the images. Besides, I was sure that I would forget them in no time. - -![Fourier transform equations][3] - -Fourier transform equations (Cristiano Fontana, [CC BY-SA 4.0][4]) - -GIMP is a great open source image editor. Although I have been using it for years, I had never investigated its batch-processing abilities nor its [Script-Fu menu][5]. This was the perfect chance to explore them. - -### What is Script-Fu? - -[Script-Fu][6] is the scripting language built into GIMP. It is an implementation of the [Scheme][7] programming language. If you have never used Scheme, give it a try, as it can be very useful. I think Script-Fu is a great way to start because it has an immediate effect on image processing, so you can feel productive very quickly. You can also write scripts in [Python][8], but Script-Fu is the default option. - -To help you get acquainted with Scheme, GIMP's documentation offers an [in-depth tutorial][9]. Scheme is a [Lisp][10]-like language, so a major characteristic is that it uses a [prefix notation][11] and a [lot of parentheses][12]. Functions and operators are applied to a list of operands by prefixing them: - - -``` -(function-name operand operand ...) - -(+ 2 3) -↳ Returns 5 - -(list 1 2 3 5) -↳ Returns a list containing 1, 2, 3, and 5 -``` - -It took me a while to find the documentation for the full list of GIMP's functions, but it was actually straightforward. In the **Help** menu, there is a **Procedure Browser** with very extensive and detailed documentation about all the possible functions. - -![GIMP Procedure Browser][13] - -(Cristiano Fontana, [CC BY-SA 4.0][4]) - -### Accessing GIMP's batch mode - -You can run GIMP with batch mode enabled by using the `-b` option. The `-b` option's argument can be the script you want to run or a dash (`-`) that makes GIMP launch in an interactive mode instead of the command line. Normally when you start GIMP, it loads its graphical user interface (GUI), but you can disable that with the `-i` option. - -### Writing your first script - -Create a file called `chalk.scm` and save it to the `scripts` folder found in the **Preferences** window under **Folders → Scripts**. In my case, it is at `$HOME/.config/GIMP/2.10/scripts`. - -Inside the `chalk.scm` file, write your first script with: - - -``` -(define (chalk filename grow-pixels spread-amount percentage) -   (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) -          (drawable (car (gimp-image-get-active-layer image))) -          (new-filename (string-append "modified_" filename))) -     (gimp-image-select-color image CHANNEL-OP-REPLACE drawable '(0 0 0)) -     (gimp-selection-grow image grow-pixels) -     (gimp-context-set-foreground '(0 0 0)) -     (gimp-edit-bucket-fill drawable BUCKET-FILL-FG LAYER-MODE-NORMAL 100 255 TRUE 0 0) -     (gimp-selection-none image) -     (plug-in-spread RUN-NONINTERACTIVE image drawable spread-amount spread-amount) -     (gimp-drawable-invert drawable TRUE) -     (plug-in-randomize-hurl RUN-NONINTERACTIVE image drawable percentage 1 TRUE 0) -     (gimp-file-save RUN-NONINTERACTIVE image drawable new-filename new-filename) -     (gimp-image-delete image))) -``` - -### Defining the script variables - -In the script, the `(define (chalk filename grow-pixels spread-amound percentage) ...)` function defines a new function called `chalk` that accepts the parameters: `filename`, `grow-pixels`, `spread-amound`, and `percentage`. Everything else inside the `define` function is the body of the `chalk` function. You might have noticed that variables with long names are spelled with dashes between the words; this is the idiomatic style of Lisp-like languages. - -The `(let* ...)` function is a special procedure that allows you to define some temporary variables that are valid only inside the body. In this case, the variables are `image`, `drawable`, and `new-filename`. It loads the image with `gimp-file-load`, which returns a list that includes the image, then it selects the first entry with the `car` function. Then, it selects the first active layer and stores its reference in the `drawable` variable. Finally, it defines the string containing the new filename of the resulting image. - -To help you better understand the procedure, I'll break it down. First, start GIMP with the GUI enabled and the Script-Fu console, which is found in **Filters → Script-Fu → Console**. In this case, you cannot use `let*` because the variables must be persistent. Define the `image` variable using the `define` function, and give it the proper path to find the image: - - -``` -`(define image (car (gimp-file-load RUN-NONINTERACTIVE "Fourier.png" "Fourier.png")))` -``` - -It appears that nothing has happened in the GUI, but the image is loaded. You need to enable the image display with: - - -``` -`(gimp-display-new image)` -``` - -![GUI with the displayed image][14] - -(Cristiano Fontana, [CC BY-SA 4.0][4]) - -Now, get the active layer and store it in the `drawable` variable: - - -``` -`(define drawable (car (gimp-image-get-active-layer image)))` -``` - -Finally, define the image's new filename: - - -``` -`(define new-filename "modified_Fourier.png")` -``` - -Here is what you should see in the Script-Fu console after running these commands: - -![Script-Fu console][15] - -(Cristiano Fontana, [CC BY-SA 4.0][4]) - -Before acting on the image, you need to define the variables that would be defined as the function arguments in the script: - - -``` -(define grow-pixels 2) -(define spread-amount 4) -(define percentage 3) -``` - -### Acting on the image - -Now that all the relevant variables are defined, you can act on the image. The script's actions can be executed directly on the console. The first step is to select the color black on the active layer. The color is written as a list of three numbers—either as `(list 0 0 0)` or `'(0 0 0)`: - - -``` -`(gimp-image-select-color image CHANNEL-OP-REPLACE drawable '(0 0 0))` -``` - -![Image with the selected color][16] - -(Cristiano Fontana, [CC BY-SA 4.0][4]) - -Grow the selection by two pixels: - - -``` -`(gimp-selection-grow image grow-pixels)` -``` - -![Image with the selected color][17] - -(Cristiano Fontana, [CC BY-SA 4.0][4]) - -Set the foreground color to black, and fill the selection with it: - - -``` -(gimp-context-set-foreground '(0 0 0)) -(gimp-edit-bucket-fill drawable BUCKET-FILL-FG LAYER-MODE-NORMAL 100 255 TRUE 0 0) -``` - -![Image with the selection filled with black][18] - -(Cristiano Fontana, [CC BY-SA 4.0][4]) - -Delete the selection: - - -``` -`(gimp-selection-none image)` -``` - -![Image with no selection][19] - -(Cristiano Fontana, [CC BY-SA 4.0][4]) - -Move the pixels around randomly: - - -``` -`(plug-in-spread RUN-NONINTERACTIVE image drawable spread-amount spread-amount)` -``` - -![Image with pixels moved around][20] - -(Cristiano Fontana, [CC BY-SA 4.0][4]) - -Invert the image colors: - - -``` -`(gimp-drawable-invert drawable TRUE)` -``` - -![Image with pixels moved around][21] - -(Cristiano Fontana, [CC BY-SA 4.0][4]) - -Randomize the pixels: - - -``` -`(plug-in-randomize-hurl RUN-NONINTERACTIVE image drawable percentage 1 TRUE 0)` -``` - -![Image with pixels moved around][22] - -(Cristiano Fontana, [CC BY-SA 4.0][4]) - -Save the image to a new file: - - -``` -`(gimp-file-save RUN-NONINTERACTIVE image drawable new-filename new-filename)` -``` - -![Equations of the Fourier transform and its inverse][23] - -Fourier transform equations (Cristiano Fontana, [CC BY-SA 4.0][4]) - -### Running the script in batch mode - -Now that you know what the script does, you can run it in batch mode: - - -``` -`gimp -i -b '(chalk "Fourier.png" 2 4 3)' -b '(gimp-quit 0)'` -``` - -After the `chalk` function runs, it calls a second function with the `-b` option to tell GIMP to quit: `gimp-quit`. - -### Learn more - -This tutorial showed you how to get started with GIMP's built-in scripting features and introduced Script-Fu, GIMP's Scheme implementation. If you want to move forward, I suggest you look at the official documentation and its [tutorial][9]. If you are not familiar with Scheme or Lisp, the syntax could be a little intimidating at first, but I suggest you give it a try anyway. It might be a nice surprise. - -Professional design software like Photoshop is terrific, but it’s also expensive. What do you do... - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/21/1/gimp-scripting - -作者:[Cristiano L. Fontana][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://opensource.com/users/cristianofontana -[b]: https://github.com/lujun9972 -[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/painting_computer_screen_art_design_creative.png?itok=LVAeQx3_ (Painting art on a computer screen) -[2]: https://www.gimp.org/ -[3]: https://opensource.com/sites/default/files/uploads/fourier.png (Fourier transform equations) -[4]: https://creativecommons.org/licenses/by-sa/4.0/ -[5]: https://docs.gimp.org/en/gimp-filters-script-fu.html -[6]: https://docs.gimp.org/en/gimp-concepts-script-fu.html -[7]: https://en.wikipedia.org/wiki/Scheme_(programming_language) -[8]: https://docs.gimp.org/en/gimp-filters-python-fu.html -[9]: https://docs.gimp.org/en/gimp-using-script-fu-tutorial.html -[10]: https://en.wikipedia.org/wiki/Lisp_%28programming_language%29 -[11]: https://en.wikipedia.org/wiki/Polish_notation -[12]: https://xkcd.com/297/ -[13]: https://opensource.com/sites/default/files/uploads/procedure_browser.png (GIMP Procedure Browser) -[14]: https://opensource.com/sites/default/files/uploads/gui01_image.png (GUI with the displayed image) -[15]: https://opensource.com/sites/default/files/uploads/console01_variables.png (Script-Fu console) -[16]: https://opensource.com/sites/default/files/uploads/gui02_selected.png (Image with the selected color) -[17]: https://opensource.com/sites/default/files/uploads/gui03_grow.png (Image with the selected color) -[18]: https://opensource.com/sites/default/files/uploads/gui04_fill.png (Image with the selection filled with black) -[19]: https://opensource.com/sites/default/files/uploads/gui05_no_selection.png (Image with no selection) -[20]: https://opensource.com/sites/default/files/uploads/gui06_spread.png (Image with pixels moved around) -[21]: https://opensource.com/sites/default/files/uploads/gui07_invert.png (Image with pixels moved around) -[22]: https://opensource.com/sites/default/files/uploads/gui08_hurl.png (Image with pixels moved around) -[23]: https://opensource.com/sites/default/files/uploads/modified_fourier.png (Equations of the Fourier transform and its inverse) From d2967e9bf2737ad23caec920714df2ef1466f84f Mon Sep 17 00:00:00 2001 From: amwps290 Date: Wed, 3 Feb 2021 10:15:12 +0800 Subject: [PATCH 02/18] translated --- ...scripts to make image processing faster.md | 271 ++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100644 translated/tech/20210126 Write GIMP scripts to make image processing faster.md diff --git a/translated/tech/20210126 Write GIMP scripts to make image processing faster.md b/translated/tech/20210126 Write GIMP scripts to make image processing faster.md new file mode 100644 index 0000000000..72007740eb --- /dev/null +++ b/translated/tech/20210126 Write GIMP scripts to make image processing faster.md @@ -0,0 +1,271 @@ +[#]: collector: (lujun9972) +[#]: translator: (amwps290) +[#]: reviewer: ( ) +[#]: publisher: ( ) +[#]: url: ( ) +[#]: subject: (Write GIMP scripts to make image processing faster) +[#]: via: (https://opensource.com/article/21/1/gimp-scripting) +[#]: author: (Cristiano L. Fontana https://opensource.com/users/cristianofontana) + +编写 GIMP 脚本使图像处理更快 +====== +通过向一批图像添加效果来学习 GIMP 的脚本语言 Script-Fu。 + +![Painting art on a computer screen][1] + +前一段时间,我想给方程图片加一个黑板式的外观。 我开始使用 [GNU Image Manipulation Program (GIMP)][2] 来处理,并对结果感到满意。 问题是我必须对图像执行几个操作,当我想再次使用此样式,不想对所有图像重复这些步骤。 此外,我确信我会很快忘记他们。 + +![Fourier transform equations][3] + +傅立叶变换方程式(Cristiano Fontana,[CC BY-SA 4.0] [4]) + +GIMP 是一个很棒的开源图像编辑器。 尽管我已经使用了多年,但从未研究过其批处理功能或 [Script-Fu][5] 菜单。 这是探索它们的绝好机会。 + +### 什么是 Script-Fu? + +[Script-Fu][6] 是 GIMP 内置的脚本语言。 是一种基于 [Scheme ][7]的编程语言。 如果您从未使用过 Scheme,请尝试一下,因为它可能非常有用。 我认为 Script-Fu 是一个很好的入门方法,因为它对图像处理具有立竿见影的效果,因此您可以非常快速地提高工作效率。 您也可以使用 [Python][8] 编写脚本,但是 Script-Fu 是默认选项。 + +为了帮助您熟悉 Scheme,GIMP 的文档提供了深入的[教程][9]。 Scheme 是一种类似于 [Lisp][10] 的语言,因此主要特征是它使用[前缀][11]表示法和[许多括号][12]。 通过为操作数和操作符添加前缀来将它们应用到操作数列表: + + +``` +(function-name operand operand ...) + +(+ 2 3) +↳ Returns 5 + +(list 1 2 3 5) +↳ Returns a list containing 1, 2, 3, and 5 +``` + +我花了一些时间才能找到 GIMP 功能完整列表的文档,但实际上很简单。 在 **Help** 菜单中,有一个 **Procedure Browser**,其中包含有关所有可能功能的非常详尽的文档。 + +![GIMP Procedure Browser][13] + +(Cristiano Fontana, [CC BY-SA 4.0][4]) + +### 使用 GIMP 的批处理模式 + +您可以使用 `-b` 选项以批处理的方式启动 GIMP. `-b` 选项的参数可以是你想要运行的脚本,或者用一个 `-` 来让 GIMP 进入交互模式而不是命令行模式。正常情况下,当你启动 GIMP 的时候,它会启动图形界面,但是你可以使用 `-i` 选项来禁用它。 + +### 开始编写你的第一个脚本 + +创建一个名为 `chalk.scm` 的文件,并把它保存在 **Preferences** 窗口中 **Folders** 选项下的 **Script** 中指定的 `script` 文件夹下。就我而言,是在 `$HOME/.config/GIMP/2.10/scripts`. + +在 `chalk.scm` 文件中,写入下面的内容: + + +``` +(define (chalk filename grow-pixels spread-amount percentage) +   (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) +          (drawable (car (gimp-image-get-active-layer image))) +          (new-filename (string-append "modified_" filename))) +     (gimp-image-select-color image CHANNEL-OP-REPLACE drawable '(0 0 0)) +     (gimp-selection-grow image grow-pixels) +     (gimp-context-set- '(0 0 0)) +     (gimp-edit-bucket-fill drawable BUCKET-FILL-FG LAYER-MODE-NORMAL 100 255 TRUE 0 0) +     (gimp-selection-none image) +     (plug-in-spread RUN-NONINTERACTIVE image drawable spread-amount spread-amount) +     (gimp-drawable-invert drawable TRUE) +     (plug-in-randomize-hurl RUN-NONINTERACTIVE image drawable percentage 1 TRUE 0) +     (gimp-file-save RUN-NONINTERACTIVE image drawable new-filename new-filename) +     (gimp-image-delete image))) +``` + +### 定义脚本变量 + +在脚本中, `(define (chalk filename grow-pixels spread-amound percentage) ...)` 函数定义了一个名叫 `chalk` 的新函数。它的函数参数是 `filename`, `grow-pixels`, `spread-amound` 和 `percentage`. 在 `define` 中的所有内容都是 `chalk` 函数的主体。你可能已经注意到,那些名字比较长的变量中间都有一个破折号来分割。这是类 Lisp 语言的惯用风格。 + +`(let* ...)` 函数是一个特殊的函数可以让你定义一些只有在这个函数体中才有效的临时变量。临时变量有 `image`, `drawable`, 以及 `new-filename`. 它使用 `gimp-file-load` 来载入图片,这会返回它所包含的图片的一个列表。并通过 `car` 函数来选取第一项。 然后,它选择第一个活动层并将其引用存储在 `drawable` 变量中。 最后,它定义了包含图像新文件名的字符串。 + +为了帮助您更好地了解该过程,我将对其进行分解。 首先,启动带 GUI 的 GIMP,然后你可以通过依次点击 **Filters → Script-Fu → Console** 来打开 Script-Fu 控制台。 在这种情况下,不能使用 `let *`,因为变量必须是持久的。 使用 `define` 函数定义 `image` 变量,并为其提供查找图像的正确路径: + + +``` +`(define image (car (gimp-file-load RUN-NONINTERACTIVE "Fourier.png" "Fourier.png")))` +``` + +似乎在 GUI 中什么也没有发生,但是图像已加载。 您需要通过以下方式来让图像显示: + + +``` +`(gimp-display-new image)` +``` + +![GUI with the displayed image][14] + +(Cristiano Fontana, [CC BY-SA 4.0][4]) + +现在,获取活动层并将其存储在 `drawable` 变量中: + + +``` +`(define drawable (car (gimp-image-get-active-layer image)))` +``` + +最后,定义图像的新文件名: + + +``` +`(define new-filename "modified_Fourier.png")` +``` + +运行命令后,您将在 Script-Fu 控制台中看到以下内容: + +![Script-Fu console][15] + +(Cristiano Fontana, [CC BY-SA 4.0][4]) + +在对图像执行操作之前,需要定义将在脚本中作为函数参数的变量: + + +``` +(define grow-pixels 2) +(define spread-amount 4) +(define percentage 3) +``` + +### 处理图片 + +现在,所有相关变量都已定义,您可以对图像进行操作了。 脚本的操作可以直接在控制台上执行。第一步是在活动层上选择黑色。 颜色被写成一个由三个数字组成的列表,即 `(list 0 0 0)` 或者是 `'(0 0 0)`: + + +``` +`(gimp-image-select-color image CHANNEL-OP-REPLACE drawable '(0 0 0))` +``` + +![Image with the selected color][16] + +(Cristiano Fontana, [CC BY-SA 4.0][4]) + +扩大选取两个像素: + + +``` +`(gimp-selection-grow image grow-pixels)` +``` + +![Image with the selected color][17] + +(Cristiano Fontana, [CC BY-SA 4.0][4]) + +将前景色设置为黑色,并用它填充选区: + + +``` +(gimp-context-set-foreground '(0 0 0)) +(gimp-edit-bucket-fill drawable BUCKET-FILL-FG LAYER-MODE-NORMAL 100 255 TRUE 0 0) +``` + +![Image with the selection filled with black][18] + +(Cristiano Fontana, [CC BY-SA 4.0][4]) + +删除选区: + + +``` +`(gimp-selection-none image)` +``` + +![Image with no selection][19] + +(Cristiano Fontana, [CC BY-SA 4.0][4]) + +随机移动像素: + + +``` +`(plug-in-spread RUN-NONINTERACTIVE image drawable spread-amount spread-amount)` +``` + +![Image with pixels moved around][20] + +(Cristiano Fontana, [CC BY-SA 4.0][4]) + +反转图像颜色: + + +``` +`(gimp-drawable-invert drawable TRUE)` +``` + +![Image with pixels moved around][21] + +(Cristiano Fontana, [CC BY-SA 4.0][4]) + +随机化像素: + + +``` +`(plug-in-randomize-hurl RUN-NONINTERACTIVE image drawable percentage 1 TRUE 0)` +``` + +![Image with pixels moved around][22] + +(Cristiano Fontana, [CC BY-SA 4.0][4]) + +将图像保存到新文件: + + +``` +`(gimp-file-save RUN-NONINTERACTIVE image drawable new-filename new-filename)` +``` + +![Equations of the Fourier transform and its inverse][23] + +傅立叶变换方程 (Cristiano Fontana, [CC BY-SA 4.0][4]) + +### 以批处理模式运行脚本 + +现在您知道了脚本的功能,可以在批处理模式下运行它: + + +``` +`gimp -i -b '(chalk "Fourier.png" 2 4 3)' -b '(gimp-quit 0)'` +``` + +在运行 `chalk` 函数之后,它将使用 `-b` 选项调用第二个函数 `gimp-quit` 来告诉 GIMP 退出。 + +### 了解更多 + +本教程向您展示了如何开始使用 GIMP 的内置脚本功能,并介绍了 GIMP 的 Scheme 实现的 Script-Fu。 如果您想继续前进,建议您查看官方文档及其[入门教程][9]。 如果您不熟悉 Scheme 或 Lisp,那么一开始的语法可能有点吓人,但我还是建议您尝试一下。 这可能是一个不错的惊喜。 + +Photoshop 之类的专业设计软件非常棒,但价格也很昂贵。 你会怎么做... + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/21/1/gimp-scripting + +作者:[Cristiano L. Fontana][a] +选题:[lujun9972][b] +译者:[amwps290](https://github.com/amwps290) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/cristianofontana +[b]: https://github.com/lujun9972 +[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/painting_computer_screen_art_design_creative.png?itok=LVAeQx3_ (Painting art on a computer screen) +[2]: https://www.gimp.org/ +[3]: https://opensource.com/sites/default/files/uploads/fourier.png (Fourier transform equations) +[4]: https://creativecommons.org/licenses/by-sa/4.0/ +[5]: https://docs.gimp.org/en/gimp-filters-script-fu.html +[6]: https://docs.gimp.org/en/gimp-concepts-script-fu.html +[7]: https://en.wikipedia.org/wiki/Scheme_(programming_language) +[8]: https://docs.gimp.org/en/gimp-filters-python-fu.html +[9]: https://docs.gimp.org/en/gimp-using-script-fu-tutorial.html +[10]: https://en.wikipedia.org/wiki/Lisp_%28programming_language%29 +[11]: https://en.wikipedia.org/wiki/Polish_notation +[12]: https://xkcd.com/297/ +[13]: https://opensource.com/sites/default/files/uploads/procedure_browser.png (GIMP Procedure Browser) +[14]: https://opensource.com/sites/default/files/uploads/gui01_image.png (GUI with the displayed image) +[15]: https://opensource.com/sites/default/files/uploads/console01_variables.png (Script-Fu console) +[16]: https://opensource.com/sites/default/files/uploads/gui02_selected.png (Image with the selected color) +[17]: https://opensource.com/sites/default/files/uploads/gui03_grow.png (Image with the selected color) +[18]: https://opensource.com/sites/default/files/uploads/gui04_fill.png (Image with the selection filled with black) +[19]: https://opensource.com/sites/default/files/uploads/gui05_no_selection.png (Image with no selection) +[20]: https://opensource.com/sites/default/files/uploads/gui06_spread.png (Image with pixels moved around) +[21]: https://opensource.com/sites/default/files/uploads/gui07_invert.png (Image with pixels moved around) +[22]: https://opensource.com/sites/default/files/uploads/gui08_hurl.png (Image with pixels moved around) +[23]: https://opensource.com/sites/default/files/uploads/modified_fourier.png (Equations of the Fourier transform and its inverse) From 7c33f69ada4d309128c25b9d5d20d2416fe52398 Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Wed, 3 Feb 2021 10:58:43 +0800 Subject: [PATCH 03/18] PRF @MjSeven --- .../20201013 My first day using Ansible.md | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/translated/tech/20201013 My first day using Ansible.md b/translated/tech/20201013 My first day using Ansible.md index 4182d6fa45..93bc08d699 100644 --- a/translated/tech/20201013 My first day using Ansible.md +++ b/translated/tech/20201013 My first day using Ansible.md @@ -1,6 +1,6 @@ [#]: collector: "lujun9972" [#]: translator: "MjSeven" -[#]: reviewer: " " +[#]: reviewer: "wxy" [#]: publisher: " " [#]: url: " " [#]: subject: "My first day using Ansible" @@ -9,16 +9,18 @@ 使用 Ansible 的第一天 ====== -一名系统管理员分享了如何使用 Ansible 在网络中配置计算机并把其带入实际工作的信息和建议。 -![People work on a computer server with devices][1] -无论是第一次还是第五十次,启动并运行一台新的物理或虚拟计算机都非常耗时,而且需要大量的工作。多年来,我一直使用我创建的一系列脚本和 RPM 来安装所需的软件包,并为我喜欢的工具配置选项。这种方法效果很好,简化了我的工作,而且还减少了在键盘上输入命令的时间。 +> 一名系统管理员分享了如何使用 Ansible 在网络中配置计算机并把其带入实际工作的信息和建议。 -我一直在寻找更好的工作方式。近几年来,我一直在听到并且读到有关 [Ansible][2] 的信息,它是一个自动配置和管理系统的强大工具。Ansible 允许系统管理员在一个或多个剧本中为每个主机指定一个特定状态,然后执行使主机进入该状态的所有任务。包括安装或删除各种资源,例如 RPM 或 Apt 软件包、配置和其它文件、用户、组等等。 +![](https://img.linux.net.cn/data/attachment/album/202102/03/105826sn41jj0i8evu19nn.jpg) + +无论是第一次还是第五十次,启动并运行一台新的物理或虚拟计算机都非常耗时,而且需要大量的工作。多年来,我一直使用我创建的一系列脚本和 RPM 来安装所需的软件包,并为我喜欢的工具配置各种选项。这种方法效果很好,简化了我的工作,而且还减少了在键盘上输入命令的时间。 + +我一直在寻找更好的工作方式。近几年来,我一直在听到并且读到有关 [Ansible][2] 的信息,它是一个自动配置和管理系统的强大工具。Ansible 允许系统管理员在一个或多个剧本playbook中为每个主机指定一个特定状态,然后执行各种必要的任务,使主机进入该状态。这包括安装或删除各种资源,例如 RPM 或 Apt 软件包、配置文件和其它文件、用户、组等等。 因为一些琐事,我推迟了很长一段时间学习如何使用它。直到最近,我遇到了一个我认为 Ansible 可以轻松解决的问题。 -这篇文章并不会完整地告诉你如何入门 Ansible,相反,它只是对我遇到的问题和我在一些隐秘的地方发现的信息的做一些记录。我在各种在线讨论和问答小组中找到的有关 Ansible 的许多信息都是错误的。错误范围包括明显的老旧信息(没有任何日期或来源的迹象),还有一些是完全错误的信息。 +这篇文章并不会完整地告诉你如何入门 Ansible,相反,它只是对我遇到的问题和我在一些隐秘的地方发现的信息的做了一些记录。我在各种在线讨论和问答小组中找到的有关 Ansible 的许多信息都是错误的。错误范围包括明显的老旧信息(没有任何日期或来源的迹象),还有一些是完全错误的信息。 本文所介绍的内容是有用的,尽管可能还有其它方法可以完成相同的事情,但我使用的是 Ansible 2.9.13 和 [Python][3] 3.8.5。 @@ -32,13 +34,13 @@ ### 开始 -我读过许多有关 Ansible 的好文章和书籍,但从来没有遇到过“我必须把这个用到工作中”那种情况。但是,现在就是这种情况。 +我读过许多有关 Ansible 的好文章和书籍,但从来没有在“我必须现在就把这个做好!”的情况下读过。而现在 —— 好吧,就是现在! 在重读这些文档时,我发现它们主要是在讨论如何从 GitHub 开始安装并使用 Ansible,这很酷。但是我真的只是想尽快开始,所以我使用 DNF 和 Fedora 仓库中的版本在我的 Fedora 工作站上安装了它,非常简单。 但是后来我开始寻找文件位置,并尝试确定需要修改哪些配置文件、将我的剧本保存在什么位置,甚至一个剧本怎么写以及它的作用,我脑海中有一大堆(到目前为止)悬而未决的问题。 -因此,在没有进一步描述我的困难的情况下,以下是我发现的东西以及促使我继续前进的东西。 +因此,不不需要进一步描述我的困难的情况下,以下是我发现的东西以及促使我继续前进的东西。 ### 配置 @@ -46,9 +48,9 @@ Ansible 的配置文件保存在 `/etc/ansible` 中,这很有道理,因为 ` #### ansible.cfg -在进行文档和线上找到的一些实践练习之后,我遇到了一些有关弃用某些较旧的 Python 文件的警告信息。因此,我在 `ansible.cfg` 中将 `deprecation_warnings` 设置为 `false`,这样那些愤怒的红色警告消息就不会出现了: +在进行了从文档和线上找到的一些实践练习之后,我遇到了一些有关弃用某些较旧的 Python 文件的警告信息。因此,我在 `ansible.cfg` 中将 `deprecation_warnings` 设置为 `false`,这样那些愤怒的红色警告消息就不会出现了: -```bash +``` deprecation_warnings = False ``` @@ -56,28 +58,28 @@ deprecation_warnings = False #### hosts 文件 -与 `/etc/hosts` 文件不同,`hosts` 文件也被称为清单文件,它列出了网络上的主机。此文件允许将主机分组到相关集合中,例如服务器、工作站和任何你所需的名称。这个文件包含帮助和大量示例,所以我在这里就不详细介绍了。但是,有些事情你必须知道。 +与 `/etc/hosts` 文件不同,`hosts` 文件也被称为清单inventory文件,它列出了网络上的主机。此文件允许将主机分组到相关集合中,例如“servers”、“workstations”和任何你所需的名称。这个文件包含帮助和大量示例,所以我在这里就不详细介绍了。但是,有些事情你必须知道。 -主机可以在任何组之外列出,但是组对于识别具有一个或多个共同特征的主机很有帮助。组使用 INI 格式,所以服务器组看起来像这样: +主机也可以列在组之外,但是组对于识别具有一个或多个共同特征的主机很有帮助。组使用 INI 格式,所以服务器组看起来像这样: ``` [servers] server1 server2 -...etc. +...... ``` -这个文件中必须有一个主机名,这样 Ansible 才能对它进行操作。尽管有些子命令允许指定主机名,但除非主机名在 `hosts` 文件中,否则命令会失败。一个主机也可以在多个组中。因此,除了 `[servers]` 组之外,`server1` 也可能是 `[webservers]` 组的成员,还可以是 `[ubuntu]` 组的成员,这样以区别于 Fedora 服务器。 +这个文件中必须有一个主机名,这样 Ansible 才能对它进行操作。即使有些子命令允许指定主机名,但除非主机名在 `hosts` 文件中,否则命令会失败。一个主机也可以放在多个组中。因此,除了 `[servers]` 组之外,`server1` 也可能是 `[webservers]` 组的成员,还可以是 `[ubuntu]` 组的成员,这样以区别于 Fedora 服务器。 -Ansible 很智能。如果 `all` 参数用作主机名,Ansible 会扫描 `hosts` 文件并在它列出的所有主机上执行定义的任务。Ansible 只会尝试在每个主机上工作一次,不管它出现在多少个组中。这也意味着不需要定义 "all" 组,因为 Ansible 可以确定文件中的所有主机名,并创建自己唯一的主机名列表。 +Ansible 很智能。如果 `all` 参数用作主机名,Ansible 会扫描 `hosts` 文件并在它列出的所有主机上执行定义的任务。Ansible 只会尝试在每个主机上工作一次,不管它出现在多少个组中。这也意味着不需要定义 `all` 组,因为 Ansible 可以确定文件中的所有主机名,并创建自己唯一的主机名列表。 -另一件需要注意的事情是单个主机的多个条目。我在 DNS 文件中使用 `CNAME` 记录来创建别名,这些别名指向某些主机的 [A 记录][5],这样,我可以将一个主机称为 `host1` 或 `h1` 或 `myhost`。如果你在 `hosts` 文件中为同一主机指定多个主机名,则 Ansible 将尝试在所有这些主机名上执行其任务,它无法知道它们指向同一主机。好消息是,这并不会影响整体结果;它只是多花了一点时间,因为 Ansible在辅助主机名上工作,它会确定所有操作均已执行。 +另一件需要注意的事情是单个主机的多个条目。我在 DNS 文件中使用 `CNAME` 记录来创建别名,这些别名指向某些主机的 [A 记录][5],这样,我可以将一个主机称为 `host1` 或 `h1` 或 `myhost`。如果你在 `hosts` 文件中为同一主机指定多个主机名,则 Ansible 将尝试在所有这些主机名上执行其任务,它无法知道它们指向同一主机。好消息是,这并不会影响整体结果;它只是多花了一点时间,因为 Ansible 会在次要主机名上工作,它会确定所有操作均已执行。 -### Ansible facts +### Ansible 实情 -我阅读过 Ansible 的大多数材料都谈到了 [Ansible facts][6],它是与远程系统相关的数据,包括操作系统、IP 地址、文件系统等等。这些信息可以通过其它方式获得,如 `lshw`、`dmidecode` 或 `/proc` 文件系统等。但是 Ansible 会生成一个包含此信息的 JSON 文件。每次 Ansible 运行时,它都会生成这些数据。在这个数据流中,有大量的信息都是键值对形式:`<"变量名": "值">`。所有这些变量都可以在 Ansible 剧本中使用,理解海量信息的最好方法是亲自实践: +我阅读过 Ansible 的大多数材料都谈到了 Ansible [实情][6]facts,它是与远程系统相关的数据,包括操作系统、IP 地址、文件系统等等。这些信息可以通过其它方式获得,如 `lshw`、`dmidecode` 或 `/proc` 文件系统等。但是 Ansible 会生成一个包含此信息的 JSON 文件。每次 Ansible 运行时,它都会生成这些实情数据。在这个数据流中,有大量的信息,都是以键值对形式出现的:`<"variable-name": "value">`。所有这些变量都可以在 Ansible 剧本中使用,理解大量可用信息的最好方法是实际显示一下: -```bash +``` # ansible -m setup | less ``` @@ -85,23 +87,23 @@ Ansible 很智能。如果 `all` 参数用作主机名,Ansible 会扫描 `host ### 模块 -`ansible` 命令使用 `-m` 选项来指定 `setup` 模块。Ansible 已经内置了许多模块,所以你不需要使用 -m。也可以安装许多下载的模块,但是内置模块可以完成我目前项目所需的一切。 +上面的 `ansible` 命令使用 `-m` 选项来指定 `setup` 模块。Ansible 已经内置了许多模块,所以你对这些模块不需要使用 `-m`。也可以安装许多下载的模块,但是内置模块可以完成我目前项目所需的一切。 ### 剧本 -剧本可以放在任何地方。因为我需要以 root 身份运行,所以我将它放在了 `/root/ansible` 下。当我运行 Ansible 时,只要这个目录是当前的工作目录(PWD),它就可以找到我的剧本。Ansible 还有一个选项,用于在运行时指定其它剧本和位置。 +剧本playbook几乎可以放在任何地方。因为我需要以 root 身份运行,所以我将它放在了 `/root/ansible` 下。当我运行 Ansible 时,只要这个目录是当前的工作目录(PWD),它就可以找到我的剧本。Ansible 还有一个选项,用于在运行时指定不同的剧本和位置。 -剧本可以包含注释,但是我看到的文章或书籍很少提及此。作为一个相信记录的系统管理员,我发现使用注释很有帮助。这并不是和任务名称做同样的事情,而是要确定任务组的目的,并确保我以某种方式或顺序记录我做这些事情的原因。当我可能忘记最初的想法时,这可以帮助以后解决调试问题。 +剧本可以包含注释,但是我看到的文章或书籍很少提及此。但作为一个相信记录一切的系统管理员,我发现使用注释很有帮助。这并不是说在注释中做和任务名称同样的事情,而是要确定任务组的目的,并确保我以某种方式或顺序记录我做这些事情的原因。当我可能忘记最初的想法时,这可以帮助以后解决调试问题。 -剧本只是定义主机所需状态的任务集合。在剧本的开头指定主机名或目录组,并定义 Ansible 将在其上运行剧本的主机。 +剧本只是定义主机所需状态的任务集合。在剧本的开头指定主机名或清单组,并定义 Ansible 将在其上运行剧本的主机。 以下是我的一个剧本示例: -```bash +``` ################################################################################ # This Ansible playbook updates Midnight commander configuration files.        # ################################################################################ -\- name: Update midnight commander configuration files +- name: Update midnight commander configuration files   hosts: all     tasks: @@ -149,19 +151,18 @@ Ansible 很智能。如果 `all` 参数用作主机名,Ansible 会扫描 `host       mode: 0644       owner: root       group: root -<SNIP> +<截断> ``` 剧本从它自己的名字和它将要操作的主机开始,在本文中,所有主机都在我的 `hosts` 文件中。`tasks` 部分列出了使主机达到所需状态的特定任务。这个剧本从使用 DNF 更新 Midnight Commander 开始(如果它不是最新的版本的话)。下一个任务确保创建所需的目录(如果它们不存在),其余任务将文件复制到合适的位置,这些 `file` 和 `copy` 任务还可以为目录和文件设置所有权和文件模式。 剧本细节超出了本文的范围,但是我对这个问题使用了一点蛮力。还有其它方法可以确定哪些用户需要更新文件,而不是对每个用户的每个文件使用一个任务。我的下一个目标是简化这个剧本,使用一些更先进的技术。 -运行剧本很容易,只需要使用 `ansible-playbook` 命令。.yml 扩展名代表 YAML,我看到过它的几种不同含义,但我认为它是“另一种标记语言”,尽管有些人声称 YAML 不是这种语言。 +运行剧本很容易,只需要使用 `ansible-playbook` 命令。`.yml` 扩展名代表 YAML,我看到过它的几种不同含义,但我认为它是“另一种标记语言Yet Another Markup Language”,尽管有些人声称 YAML 不是这种语言。 这个命令将会运行剧本,它会更新 Midnight Commander 文件: - -```bash +``` # ansible-playbook -f 10 UpdateMC.yml ``` @@ -171,12 +172,11 @@ Ansible 很智能。如果 `all` 参数用作主机名,Ansible 会扫描 `host 剧本运行时会列出每个任务和执行结果。`ok` 代表任务管理的机器状态已经完成,因为在任务中定义的状态已经为真,所以 Ansible 不需要执行任何操作。 -`changed` 表示 Ansible 已经执行了指定的任务。在这种情况下,任务中定义的机器状态不为真,所以执行指定的操作使其为真。在彩色终端上,`TASK` 线会显示彩色。在我的咖啡色终端的主机上,`TASK` 线显示为琥珀色,`changed` 是棕色,`ok` 为绿色,错误是红色。 +`changed` 表示 Ansible 已经执行了指定的任务。在这种情况下,任务中定义的机器状态不为真,所以执行指定的操作使其为真。在彩色终端上,`TASK` 行会以彩色显示。我的终端配色为“amber-on-black”,`TASK` 行显示为琥珀色,`changed` 是棕色,`ok` 为绿色,错误是红色。 下面的输出是我最终用于在新主机执行安装后配置的剧本: - -```bash +``` PLAY [Post-installation updates, package installation, and configuration] TASK [Gathering Facts] @@ -205,16 +205,16 @@ changed: [testvm2] => (item=/root/ansible/PostInstallMain/files/MidnightComma TASK [create ~/.config/mc directory in /etc/skel] changed: [testvm2] -<SNIP> +<截断> ``` ### cowsay -如果你的计算机上安装了 [cowsay][7] 程序,你会发现 `TASK` 的名字出现在奶牛的语音泡泡中: +如果你的计算机上安装了 [cowsay][7] 程序,你会发现 `TASK` 的名字出现在奶牛的语音泡泡中: ```  ____________________________________ -< TASK [Ensure we have connectivity] > +< TASK [Ensure we have connectivity] >  ------------------------------------         \   ^__^          \  (oo)\\_______ @@ -244,19 +244,19 @@ changed: [testvm2]     └── UpdateMC.yml ``` -你可以使用任何结构。但是请注意,其它系统管理员可能需要使用你设置的剧本来工作,所以目录应该具有一定程度的逻辑。当我使用 RPM 和 Bash 脚本执行安装任务后,我的文件仓库有点分散,而且绝对没有任何逻辑结构。当我为许多管理任务创建剧本时,我将介绍一个更有逻辑的结构来管理我的目录。 +你可以使用任何结构。但是请注意,其它系统管理员可能需要使用你设置的剧本来工作,所以目录应该具有一定程度的逻辑。当我使用 RPM 和 Bash 脚本执行安装任务后,我的文件仓库有点分散,绝对没有任何逻辑结构。当我为许多管理任务创建剧本时,我将介绍一个更有逻辑的结构来管理我的目录。 -### 多个剧本运行 +### 多次运行剧本 根据需要或期望多次运行剧本是安全的。只有当主机状态与任务中指定的状态不匹配时,才会执行每个任务。这使得很容易从先前的剧本运行中遇到的错误中恢复。因为当剧本遇到错误时,它将停止运行。 -在测试我的第一个剧本时,我犯了很多错误并改正了它们。假设我的修正正确,那么剧本每次运行,都会跳过那些状态已与指定状态匹配的任务,执行不匹配状态的任务。当我的修复程序起作用时,前面失败的任务将成功完成,并且会执行此任务之后的任务--直到遇到另一个错误。 +在测试我的第一个剧本时,我犯了很多错误并改正了它们。假设我的修正正确,那么剧本每次运行,都会跳过那些状态已与指定状态匹配的任务,执行不匹配状态的任务。当我的修复程序起作用时,之前失败的任务就会成功完成,并且会执行此任务之后的任务 —— 直到遇到另一个错误。 这使得测试变得容易。我可以添加新任务,并且在运行剧本时,只有新任务会被执行,因为它们是唯一与测试主机期望状态不匹配的任务。 -### 一些想法 +### 一些思考 -有些任务不适合用 Ansible,因为有更好的方法可以实现特定的计算机状态。我想到的场景是使 VM 返回到初始状态,以便可以多次使用它来执行从已知状态开始的测试。让 VM 进入特定状态,然后对此时的计算机状态进行快照要容易得多。还原到该快照通常比 Ansible 将主机返回到之前状态相比,还原到快照通常会更容易且更快。在研究文章或测试新代码时,我每天都会做几次这样的事情。 +有些任务不适合用 Ansible,因为有更好的方法可以实现特定的计算机状态。我想到的场景是使 VM 返回到初始状态,以便可以多次使用它来执行从已知状态开始的测试。让 VM 进入特定状态,然后对此时的计算机状态进行快照要容易得多。还原到该快照与 Ansible 将主机返回到之前状态相比,通常还原到快照通常会更容易且更快。在研究文章或测试新代码时,我每天都会做几次这样的事情。 在完成用于更新 Midnight Commander 的剧本之后,我创建了一个新的剧本,用于在新安装的 Fedora 主机上执行安装任务。我已经取得了不错的进步,剧本比我第一个的更加复杂,但没有那么粗暴。 @@ -268,7 +268,7 @@ changed: [testvm2] 我找到的最完整、最有用的参考文档是 Ansible 网站上的[用户指南][9]。本文仅供参考,不作为入门文档。 -多年来,Opensource.com 已经发布了许多[有关 Ansible 的文章][10],我发现其中大多数对我的需求很有帮助。Enable Sysadmin 网站上也有很多对我有帮助 [Ansible 文章][11]。你可以通过查看本周(2020 年 10 月 13 日至 14 日)的 [AnsibleFest][12] 了解更多信息。该活动完全是虚拟的,可以免费注册。 +多年来,我们已经发布了许多[有关 Ansible 的文章][10],我发现其中大多数对我的需求很有帮助。Enable Sysadmin 网站上也有很多对我有帮助 [Ansible 文章][11]。你可以通过查看本周(2020 年 10 月 13 日至 14 日)的 [AnsibleFest][12] 了解更多信息。该活动完全是线上的,可以免费注册。 -------------------------------------------------------------------------------- @@ -277,7 +277,7 @@ via: https://opensource.com/article/20/10/first-day-ansible 作者:[David Both][a] 选题:[lujun9972][b] 译者:[MjSeven](https://github.com/MjSeven) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 From 00e8afc43cfa939387c908a5e54d0ab2cb01df78 Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Wed, 3 Feb 2021 10:59:36 +0800 Subject: [PATCH 04/18] PUB @MjSeven https://linux.cn/article-13079-1.html --- .../tech => published}/20201013 My first day using Ansible.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename {translated/tech => published}/20201013 My first day using Ansible.md (99%) diff --git a/translated/tech/20201013 My first day using Ansible.md b/published/20201013 My first day using Ansible.md similarity index 99% rename from translated/tech/20201013 My first day using Ansible.md rename to published/20201013 My first day using Ansible.md index 93bc08d699..990ddc1f24 100644 --- a/translated/tech/20201013 My first day using Ansible.md +++ b/published/20201013 My first day using Ansible.md @@ -1,8 +1,8 @@ [#]: collector: "lujun9972" [#]: translator: "MjSeven" [#]: reviewer: "wxy" -[#]: publisher: " " -[#]: url: " " +[#]: publisher: "wxy" +[#]: url: "https://linux.cn/article-13079-1.html" [#]: subject: "My first day using Ansible" [#]: via: "https://opensource.com/article/20/10/first-day-ansible" [#]: author: "David Both https://opensource.com/users/dboth" From f150ca065668c192e785b91d35c1cab7f2c5e4b7 Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Wed, 3 Feb 2021 12:03:03 +0800 Subject: [PATCH 05/18] PRF @geekpi --- ...25 Use Joplin to find your notes faster.md | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/translated/tech/20210125 Use Joplin to find your notes faster.md b/translated/tech/20210125 Use Joplin to find your notes faster.md index 212025a919..e6a530e170 100644 --- a/translated/tech/20210125 Use Joplin to find your notes faster.md +++ b/translated/tech/20210125 Use Joplin to find your notes faster.md @@ -1,6 +1,6 @@ [#]: collector: (lujun9972) [#]: translator: (geekpi) -[#]: reviewer: ( ) +[#]: reviewer: (wxy) [#]: publisher: ( ) [#]: url: ( ) [#]: subject: (Use Joplin to find your notes faster) @@ -9,20 +9,22 @@ 使用 Joplin 更快地找到你的笔记 ====== -在多个手写和数字平台上整理笔记是一个严峻的挑战。这里有一个小技巧,可以更好地组织你的笔记,并快速找到你需要的东西。 -![Working from home at a laptop][1] + +> 在多个手写和数字平台上整理笔记是一个严峻的挑战。这里有一个小技巧,可以更好地组织你的笔记,并快速找到你需要的东西。 + +![](https://img.linux.net.cn/data/attachment/album/202102/03/120141dkiqil1vlqiz6wql.jpg) 在前几年,这个年度系列涵盖了单个的应用。今年,我们除了关注 2021 年的策略外,还将关注一体化解决方案。欢迎来到 2021 年 21 天生产力的第十五天。 -保持生产力也意味着(在某种程度上)要有足够的组织能力,以便找到笔记并在需要时参考它们。这不仅是对我自己的挑战,也是我交谈的很多人的挑战。 +保持生产力也意味着(在某种程度上)要有足够的组织能力,以便找到笔记并在需要时参考它们。这不仅是对我自己的挑战,也是与我交谈的很多人的挑战。 -多年来,我在应用中单独或使用数字笔记、纸质笔记、便签、数字便签、word 文档、纯文本文件以及一堆我忘记的其他格式的组合。这不仅让寻找笔记变得困难,而且知道把它们放在哪里是一个更大的挑战。 +多年来,我在应用中单独或使用数字笔记、纸质笔记、便签、数字便签、Word 文档、纯文本文件以及一堆我忘记的其他格式的组合。这不仅让寻找笔记变得困难,而且知道把它们放在哪里是一个更大的挑战。 ![Stacks of paper notes on a desk][2] -一堆笔记 (Jessica Cherry, [CC BY-SA 4.0][3]) +*一堆笔记 (Jessica Cherry, [CC BY-SA 4.0][3])* -还有就是做笔记最重要的一点:如果你以后找不到它,笔记就没有任何价值。知道含有你所需信息的笔记存在于你保存笔记的_某处_,根本没有任何帮助。 +还有就是做笔记最重要的一点:如果你以后找不到它,笔记就没有任何价值。知道含有你所需信息的笔记存在于你保存笔记的*某处*,根本没有任何帮助。 我是如何为自己解决这个问题的呢?正如他们所说,这是一个过程,我希望这也是一个对其他人有效的过程。 @@ -30,13 +32,13 @@ ![Man holding a binder full of notes][4] -三年多的笔记 (Kevin Sonney, [CC BY-SA 4.0][3]) +*三年多的笔记 (Kevin Sonney, [CC BY-SA 4.0][3])* -为了保存我的数字笔记,我需要将它们全部集中到一个地方。这个工具需要能够从多种设备上访问,具有有用的搜索功能,并且能够导出或共享我的笔记。在尝试了很多很多不同的选项之后,我选择了 [Joplin][5]。Joplin 可以让我用 markdown 写笔记,有一个相当不错的搜索功能,有适用于所有操作系统(包括手机)的应用,并支持几种不同的设备同步方式。另外,它还有文件夹_和_标签,因此我可以按照对我有意义的方式将笔记分组。 +为了保存我的数字笔记,我需要将它们全部集中到一个地方。这个工具需要能够从多种设备上访问,具有有用的搜索功能,并且能够导出或共享我的笔记。在尝试了很多很多不同的选项之后,我选择了 [Joplin][5]。Joplin 可以让我用 Markdown 写笔记,有一个相当不错的搜索功能,有适用于所有操作系统(包括手机)的应用,并支持几种不同的设备同步方式。另外,它还有文件夹*和*标签,因此我可以按照对我有意义的方式将笔记分组。 ![Organized Joplin notes management page][6] -我的 Joplin +*我的 Joplin* 我花了一些时间才把所有的东西都放在我想要的地方,但最后,这真的是值得的。现在,我可以找到我所做的笔记,而不是让它们散落在我的办公室、不同的机器和各种服务中。 @@ -47,7 +49,7 @@ via: https://opensource.com/article/21/1/notes-joplin 作者:[Kevin Sonney][a] 选题:[lujun9972][b] 译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 From 625e651be6e26461ea53894f190bd365c6dfca97 Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Wed, 3 Feb 2021 12:03:41 +0800 Subject: [PATCH 06/18] PUB @geekpi https://linux.cn/article-13080-1.html --- .../20210125 Use Joplin to find your notes faster.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename {translated/tech => published}/20210125 Use Joplin to find your notes faster.md (98%) diff --git a/translated/tech/20210125 Use Joplin to find your notes faster.md b/published/20210125 Use Joplin to find your notes faster.md similarity index 98% rename from translated/tech/20210125 Use Joplin to find your notes faster.md rename to published/20210125 Use Joplin to find your notes faster.md index e6a530e170..13e6be8bdf 100644 --- a/translated/tech/20210125 Use Joplin to find your notes faster.md +++ b/published/20210125 Use Joplin to find your notes faster.md @@ -1,8 +1,8 @@ [#]: collector: (lujun9972) [#]: translator: (geekpi) [#]: reviewer: (wxy) -[#]: publisher: ( ) -[#]: url: ( ) +[#]: publisher: (wxy) +[#]: url: (https://linux.cn/article-13080-1.html) [#]: subject: (Use Joplin to find your notes faster) [#]: via: (https://opensource.com/article/21/1/notes-joplin) [#]: author: (Kevin Sonney https://opensource.com/users/ksonney) From e120fbcb0875d74af95bee7c7f771fafc82bf83e Mon Sep 17 00:00:00 2001 From: amwps290 Date: Wed, 3 Feb 2021 14:21:04 +0800 Subject: [PATCH 07/18] Delete 20210120 Learn JavaScript by writing a guessing game.md --- ...n JavaScript by writing a guessing game.md | 300 ------------------ 1 file changed, 300 deletions(-) delete mode 100644 sources/tech/20210120 Learn JavaScript by writing a guessing game.md diff --git a/sources/tech/20210120 Learn JavaScript by writing a guessing game.md b/sources/tech/20210120 Learn JavaScript by writing a guessing game.md deleted file mode 100644 index a285bf45cf..0000000000 --- a/sources/tech/20210120 Learn JavaScript by writing a guessing game.md +++ /dev/null @@ -1,300 +0,0 @@ -[#]: collector: (lujun9972) -[#]: translator: (amwps290) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) -[#]: subject: (Learn JavaScript by writing a guessing game) -[#]: via: (https://opensource.com/article/21/1/learn-javascript) -[#]: author: (Mandy Kendall https://opensource.com/users/mkendall) - -Learn JavaScript by writing a guessing game -====== -Take the first steps toward creating interactive, dynamic web content by -practicing some basic JavaScript concepts with a simple game. -![Javascript code close-up with neon graphic overlay][1] - -It's pretty safe to say that most of the modern web would not exist without [JavaScript][2]. It's one of the three standard web technologies (along with HTML and CSS) and allows anyone to create much of the interactive, dynamic content we have come to expect in our experiences with the World Wide Web. From frameworks like [React][3] to data visualization libraries like [D3][4], it's hard to imagine the web without it. - -There's a lot to learn, and a great way to begin learning this popular language is by writing a simple application to become familiar with some concepts. Recently, some Opensource.com correspondents have written about how to learn their favorite language by writing a simple guessing game, so that's a great place to start! - -### Getting started - -JavaScript comes in many flavors, but I'll start with the basic version, commonly called "Vanilla JavaScript." JavaScript is primarily a client-side scripting language, so it can run in any standard browser without installing anything. All you need is a code editor ([Brackets][5] is a great one to try) and the web browser of your choice. - -### HTML user interface - -JavaScript runs in a web browser and interacts with the other standard web technologies, HTML and CSS. To create this game, you'll first use HTML (Hypertext Markup Language) to create a simple interface for your players to use. In case you aren't familiar, HTML is a markup language used to provide structure to content on the web. - -To start, create an HTML file for your code. The file should have the `.html` extension to let the browser know that it is an HTML document. You can call your file `guessingGame.html`. - -Use a few basic HTML tags in this file to display the game's title, instructions for how to play, interactive elements for the player to use to enter and submit their guesses, and a placeholder for providing feedback to the player: - - -``` -<!DOCTYPE> -  <[html][6]> -    <[head][7]> -      <[meta][8] charset="UTF-8" /> -      <[title][9]> JavaScript Guessing Game </[title][9]> -    </[head][7]> -    <[body][10]> -      <[h1][11]>Guess the Number!</[h1][11]> -      <[p][12]>I am thinking of a number between 1 and 100. Can you guess what it is?</[p][12]> -    -      <[label][13] for="guess">My Guess</[label][13]> -      <[input][14] type="number" id="guess"> -      <[input][14] type="submit" id="submitGuess" value="Check My Guess"> -    -      <[p][12] id="feedback"></[p][12]> -    </[body][10]> -  </[html][6]> -``` - -The `

` and `

` elements let the browser know what type of text to display on the page. The set of `

` tags signifies that the text between those two tags (`Guess the Number!`) is a heading. The set of `

` tags that follow signify that the short block of text with the instructions is a paragraph. The empty set of `

` tags at the end of this code block serve as a placeholder for the feedback the game will give the player based on their guess. - -### The <script> tag - -There are many ways to include JavaScript in a web page, but for a short script like this one, you can use a set of `