clone url: git://


1 <!DOCTYPE html>
2 <html xmlns="" lang="en" xml:lang="en">
3 <head>
4 <meta charset="utf-8" />
5 <meta name="generator" content="pandoc" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
7 <title>Redesigning my paste service with Fennel</title>
8 <style>
9 code{white-space: pre-wrap;}
10 span.smallcaps{font-variant: small-caps;}
11 span.underline{text-decoration: underline;}
12 div.column{display: inline-block; vertical-align: top; width: 50%;}
13 div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
14 ul.task-list{list-style: none;}
15 </style>
16 <style>
17 body {
18 line-height: 1.5;
19 font-family: sans-serif;
20 font-size: 18px;
21 margin: 20px auto;
22 max-width: 630px;
23 }
25 a {
26 color: blue;
27 }
29 code, pre {
30 background-color: #fddee3;
31 font-size: 14px;
32 }
34 pre {
35 padding: 25px 25px;
36 overflow: auto;
37 }
39 pre code {
40 white-space: pre;
41 }
43 img {
44 max-width: 100%;
45 }
47 table {
48 border-collapse: collapse;
49 }
51 table caption {
52 font-weight: bold;
53 margin: 10px 0px;
54 text-align: left;
55 }
57 th, td {
58 border: 1px solid #000;
59 padding: 4px;
60 }
62 blockquote {
63 border-left: 3px solid #000;
64 padding-left: 10px;
65 }
67 .border {
68 border: 1px solid #000;
69 margin: 25px 0px;
70 padding: 5px 25px;
71 }
73 @media only screen and (max-width: 700px) {
74 body {
75 margin: 10px;
76 }
77 }
79 @media (prefers-color-scheme: dark) {
80 body {
81 background-color: #111;
82 color: #eee;
83 }
84 a {
85 color: #009fff;
86 }
87 code, pre {
88 background-color: #111;
89 color: #fd6363;
90 }
91 pre {
92 padding: 15px 25px;
93 }
94 blockquote {
95 border-left: 3px solid #666;
96 }
97 .border, th, td {
98 border: 1px solid #666;
99 }
100 }
101 </style>
102 </head>
103 <body>
104 <main>
105 <h2 id="redesigning-my-paste-service-with-fennel">Redesigning my paste service with Fennel</h2>
106 <p>2021-01-21 00:00</p>
107 <p>So, in my previous post, I wrote about my paste service setup using Vim, nginx, and rsync. After using the tools involved in that setup, I had realized that I didn’t like all the scripts I had to throw in my <code>~/bin/</code> and the functions I had to add inside of my <code>~/.vimrc</code>.</p>
108 <p>After a bit of thinking, I decided on a few things:</p>
109 <ul>
110 <li>I want this to be even easier to setup</li>
111 <li>I don’t want to have to bother with Let’s Encrypt’s <code>certbot</code> tool</li>
112 <li>I don’t need syntax highlighting</li>
113 <li>I want to reduce the amount of scripts required for the paste service</li>
114 <li>I want to de-clutter my <code>~/.vimrc</code></li>
115 <li>I want to write a new tool in <a href="">Fennel</a>!</li>
116 </ul>
117 <h3 id="replacing-my-subdomain-with-a-subdirectory">Replacing my subdomain with a subdirectory</h3>
118 <p>The first thing I did was learn how to create a separate directory on my server that would contain my “pastes” (files). I wanted this to appear as a subdirectory on my homepage, so my “pastes” wouldn’t clutter up my website’s source code directory. I wanted something that looked like “<code></code>”.</p>
119 <p>After figuring out how to do this, it turned it that it was actually pretty simple!</p>
120 <p>First, I setup a directory on my server where my pastes would reside:</p>
121 <pre><code>sudo mkdir -p /var/www/paste
122 sudo chown -R $USER:$USER /var/www/paste
123 sudo chmod -R 755 /var/www/paste</code></pre>
124 <p>Then, I added the following snippet to my already-made nginx configuration at <code>/etc/nginx/sites-available/</code>:</p>
125 <pre><code>location /paste {
126 alias /var/www/paste;
127 }</code></pre>
128 <p>I restarted nginx with <code>sudo systemctl restart nginx</code>, and voila!</p>
129 <p>This method removed the need to setup TSL and SSL certificates for a subdomain at <code></code> and removed the need for more nginx <code>sites-available</code> and <code>sites-enabled</code> entries.</p>
130 <h3 id="writing-a-multi-purpose-pasting-script">Writing a multi-purpose pasting script</h3>
131 <p>This was the fun part. Since I decided I didn’t need syntax highlighting, I didn’t need the functions in Vim anymore to to generate a syntax-highlighted HTML file, so I deleted those functions. This de-cluttered my <code>~/.vimrc</code>, which was what I wanted when I outlined my goals for the new setup.</p>
132 <p>I also wanted to remove the amount of scripts I used, so I moved all of them into a directory containing old, unused scripts that I wrote.</p>
133 <p>Next, I wanted to write a single script that would handle uploading source code, by appending “<code>.txt</code>” to the end of the filename, as long as it didn’t end in:</p>
134 <ul>
135 <li><code>.txt</code></li>
136 <li><code>.jpg</code></li>
137 <li><code>.png</code></li>
138 <li><code>.bmp</code></li>
139 <li><code>.svg</code></li>
140 <li><code>.gif</code></li>
141 </ul>
142 <p>This is because I wanted to be able to view, and allow others to view, the plaintext files in the browser after they were pasted. The <code>.txt</code> is there just so I don’t end up with a file called <code>cool.txt.txt</code>. It would still work, it would just be a little silly. I occasionally share screenshots and gifs with friends, so I wanted those to be rendered in the browser, so <code>.txt</code> wouldn’t append to those kinds of files.</p>
143 <p>I know there are way more file suffixes and formats than that, but I don’t find myself pasting anything but those (though I don’t remember the last time I uploaded a <code>.bmp</code> file haha).</p>
144 <p>I also wanted the script to be able to synchronize my paste directory, in case I moved files into my <code>~/dev/paste</code> directory for synchronizing, or for when I removed files.</p>
145 <p>The script, in the end, would replace the following scripts I had:</p>
146 <ul>
147 <li><code>pupload</code>: A script for uploading any given file and generating a URL I could copy and paste.</li>
148 <li><code>ptxt</code>: A script for uploading and appending <code>.txt</code> to a filename, and generating a URL I could copy and paste.</li>
149 <li><code>psync</code>: A script that would synchronize files in my paste directory at <code>~/dev/paste</code>.</li>
150 </ul>
151 <p>The result? This little Fennel script called <a href="https://%7B%7Bgit-domain%7D%7D/fpaste">fpaste</a>.</p>
152 <p>All you have to do to configure it, is change four variable values:</p>
153 <pre><code>(local ssh &quot;;)
154 (local domain &quot;;)
155 (local remote-path &quot;/var/www/paste&quot;)
156 (local local-path &quot;~/dev/paste&quot;)</code></pre>
157 <p>Slashes at the end of the <code>domain</code>, <code>remote-path</code>, and <code>local-path</code> values are optional. If slashes are present, they will be removed, if they aren’t, the script can handle that too.</p>
158 <p>The script is basically a wrapper around <code>rsync</code>. It takes a filename and “cleans” its suffix, copies it to a local paste directory, synchronizes the local paste directory with the remote paste directory, and outputs a URL to share based on the values you entered in the configuration variables!</p>
159 </main>
160 </body>
161 </html>