-
Notifications
You must be signed in to change notification settings - Fork 1
/
tag-app.html
199 lines (192 loc) · 12.1 KB
/
tag-app.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="alternate"
type="application/rss+xml"
href="https://chenyo.me/rss.xml"
title="RSS feed for https://chenyo.me">
<title>Chenyo's Blog</title>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'],['\\(','\\)']]}});
</script>
<meta name="author" content="chenyo">
<meta name="referrer" content="no-referrer">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/style.css" type="text/css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
<link rel="favicon" type="image/x-icon" href="favicon.ico">
<script src="assets/search.js"></script></head>
<body>
<div id="preamble" class="status">
<header>
<h1><a href="https://chenyo.me">Chenyo's org-static-blog</a></h1>
<nav>
<a href="https://chenyo.me">Home</a>
<a href="archive.html">Archive</a>
<a href="tags.html">Tags</a>
<div id="search-container">
<input type="text" id="search-input" placeholder="Search anywhere...">
<i class="fas fa-search search-icon"></i>
</div>
</nav>
</header></div>
<div id="content">
<h1 class="title">Posts tagged "app":</h1>
<div class="post-date">15 Aug 2024</div><h1 class="post-title"><a href="https://chenyo.me/2024-08-15-web-learning-in-practice.html">Web learning in practice</a></h1>
<nav id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#orgf558189">1. Basic html structure</a></li>
<li><a href="#orgff93d8f">2. Tags</a></li>
<li><a href="#org1ff13b7">3. Attributes</a></li>
<li><a href="#org46f484f">4. Javascript</a>
<ul>
<li><a href="#org0413058">4.1. Fetch from an HTML URL</a></li>
<li><a href="#org0a89abe">4.2. Modify a DOM</a></li>
<li><a href="#org83b7583">4.3. Syntax</a></li>
</ul>
</li>
</ul>
</div>
</nav>
<p>
This post records the basic web development knowledge I have learned in practice.
</p>
<div id="outline-container-orgf558189" class="outline-2">
<h2 id="orgf558189"><span class="section-number-2">1.</span> Basic html structure</h2>
<div class="outline-text-2" id="text-1">
<div class="org-src-container">
<pre class="src src-html"><<span style="color: #51afef;">!DOCTYPE</span> html>
<<span style="color: #c678dd;">html</span> <span style="color: #dcaeea;">lang</span>=<span style="color: #98be65;">"en"</span>>
<span style="color: #5B6268;"><!-- </span><span style="color: #5B6268;">A head</span><span style="color: #5B6268;"> --></span>
<<span style="color: #c678dd;">head</span>>
<<span style="color: #c678dd;">meta</span> <span style="color: #dcaeea;">charset</span>=<span style="color: #98be65;">"UTF-8"</span>>
<span style="color: #5B6268;"><!-- </span><span style="color: #5B6268;">to accommodate different screen size</span><span style="color: #5B6268;"> --></span>
<<span style="color: #c678dd;">meta</span> <span style="color: #dcaeea;">name</span>=<span style="color: #98be65;">"viewport"</span> <span style="color: #dcaeea;">content</span>=<span style="color: #98be65;">"width=device-width, initial-scale=1.0"</span>>
<span style="color: #5B6268;"><!-- </span><span style="color: #5B6268;">A tab name</span><span style="color: #5B6268;"> --></span>
<<span style="color: #c678dd;">title</span>><span style="font-weight: bold; text-decoration: underline;">A website</span></<span style="color: #c678dd;">title</span>>
<<span style="color: #c678dd;">link</span> <span style="color: #dcaeea;">rel</span>=<span style="color: #98be65;">"stylesheet"</span> <span style="color: #dcaeea;">href</span>=<span style="color: #98be65;">"styles.css"</span>>
</<span style="color: #c678dd;">head</span>>
<span style="color: #5B6268;"><!-- </span><span style="color: #5B6268;">A body</span><span style="color: #5B6268;"> --></span>
<<<span style="color: #c678dd;">body</span>>
<span style="color: #5B6268;"><!-- </span><span style="color: #5B6268;">A page header</span><span style="color: #5B6268;"> --></span>
<<span style="color: #c678dd;">header</span>>
<<span style="color: #c678dd;">h1</span>><span style="font-weight: bold; text-decoration: underline;">Welcome</span></<span style="color: #c678dd;">h1</span>>
</<span style="color: #c678dd;">header</span>>
<span style="color: #5B6268;"><!-- </span><span style="color: #5B6268;">A navigation panel</span><span style="color: #5B6268;"> --></span>
<<span style="color: #c678dd;">nav</span>>
<<span style="color: #c678dd;">ul</span>>
<<<span style="color: #c678dd;">li</span>><<span style="color: #c678dd;">a</span> <span style="color: #dcaeea;">href</span>=<span style="color: #98be65;">"index.html"</span>>Home</<span style="color: #c678dd;">a</span>></<span style="color: #c678dd;">li</span>>
</<span style="color: #c678dd;">ul</span>>
</<span style="color: #c678dd;">nav</span>>
<span style="color: #5B6268;"><!-- </span><span style="color: #5B6268;">The main content</span><span style="color: #5B6268;"> --></span>
<<span style="color: #c678dd;">main</span>>
<<span style="color: #c678dd;">section</span> <span style="color: #dcaeea;">id</span>=<span style="color: #98be65;">"home"</span>>
<<span style="color: #c678dd;">h2</span>><span style="font-weight: bold; font-style: italic; text-decoration: underline;">Home</span></<span style="color: #c678dd;">h2</span>>
<<span style="color: #c678dd;">p</span>>Welcome!</<span style="color: #c678dd;">p</span>>
</<span style="color: #c678dd;">section</span>>
</<span style="color: #c678dd;">main</span>>
<span style="color: #5B6268;"><!-- </span><span style="color: #5B6268;">A footer</span><span style="color: #5B6268;"> --></span>
<<span style="color: #c678dd;">footer</span>>
<<span style="color: #c678dd;">p</span>><span style="color: #dcaeea;">&copy;</span> All rights reserved.</<span style="color: #c678dd;">p</span>>
</<span style="color: #c678dd;">footer</span>>
</<span style="color: #c678dd;">body</span>>
</<span style="color: #c678dd;">html</span>>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgff93d8f" class="outline-2">
<h2 id="orgff93d8f"><span class="section-number-2">2.</span> Tags</h2>
<div class="outline-text-2" id="text-2">
<ul class="org-ul">
<li><code class="src src-html"><<span style="color: #c678dd;">a</span>></code>: contain links; have following attributes:
<ul class="org-ul">
<li><code class="src src-html"><span style="color: #dcaeea;">target</span>="_blank"</code>: open the link in a new tab.</li>
<li><code class="src src-html"><span style="color: #dcaeea;">title</span>="Go to the link"</code>: the tooltip message, i.e., the floating message when a user hovers over.</li>
</ul></li>
<li><code class="src src-html"><<span style="color: #c678dd;">span</span>></code>: don’t add line breaks before or after it.</li>
<li><code class="src src-html"><<span style="color: #c678dd;">hr</span>></code>: horizontal rule.</li>
</ul>
</div>
</div>
<div id="outline-container-org1ff13b7" class="outline-2">
<h2 id="org1ff13b7"><span class="section-number-2">3.</span> Attributes</h2>
<div class="outline-text-2" id="text-3">
<ul class="org-ul">
<li><code class="src src-html"><span style="color: #dcaeea;">id</span>="home"</code>:
<ul class="org-ul">
<li>allow specific styling of the element, e.g., <code class="src src-html">#home ul {...}</code> only styles the <code class="src src-html">ul</code> in the block with the same id.</li>
</ul></li>
</ul>
</div>
</div>
<div id="outline-container-org46f484f" class="outline-2">
<h2 id="org46f484f"><span class="section-number-2">4.</span> Javascript</h2>
<div class="outline-text-2" id="text-4">
</div>
<div id="outline-container-org0413058" class="outline-3">
<h3 id="org0413058"><span class="section-number-3">4.1.</span> Fetch from an HTML URL</h3>
<div class="outline-text-3" id="text-4-1">
<ol class="org-ol">
<li><code class="src src-js"><span style="color: #51afef;">await</span> fetch(url)</code>: returns a <code class="src src-js">Response</code> object.
<ul class="org-ul">
<li><code class="src src-js"><span style="color: #51afef;">await</span></code> waits for the method to complete.</li>
</ul></li>
<li><code class="src src-js"><span style="color: #51afef;">await</span> response.text()</code>: returns the <code class="src src-js">html</code> string.</li>
<li><code class="src src-js">DOMParser().parseFromString(postHtml, <span style="color: #98be65;">"text/html"</span>)</code>: returns a <code class="src src-js">Document</code> object, which is a complete DOM tree from the HTML string; <code class="src src-js">DOMParser</code> is a built-in browser API.</li>
<li><code class="src src-js">postDoc.getElementById(<span style="color: #98be65;">"content"</span>)</code>: returns an <code class="src src-js">Element</code> with the <code class="src src-js">content</code> id name.</li>
<li><code class="src src-js">content.querySelector(<span style="color: #98be65;">".post-title a"</span>)</code>: fetches the first <code class="src src-js">Element</code> with the <code class="src src-js">post-title</code> class name, and returns the first <code class="src src-js">Element</code> the first <code class="src src-js"><a></code> (anchor) tag.
<ul class="org-ul">
<li><code class="src src-js">.</code> for classes, <code class="src src-js">#</code> for IDs (IDs should be unique within a page)</li>
</ul></li>
</ol>
</div>
</div>
<div id="outline-container-org0a89abe" class="outline-3">
<h3 id="org0a89abe"><span class="section-number-3">4.2.</span> Modify a DOM</h3>
<div class="outline-text-3" id="text-4-2">
<ul class="org-ul">
<li><code class="src src-js">content.querySelector(<span style="color: #98be65;">".taglist"</span>).remove()</code>: removes the element from the DOM, i.e., it modifies <code class="src src-js">content</code>.</li>
</ul>
</div>
</div>
<div id="outline-container-org83b7583" class="outline-3">
<h3 id="org83b7583"><span class="section-number-3">4.3.</span> Syntax</h3>
<div class="outline-text-3" id="text-4-3">
<ul class="org-ul">
<li><code class="src src-js"><span style="color: #51afef;">const</span> <span style="color: #dcaeea;">escapedQuery</span> = query.replace(<span style="color: #98be65;">/[.*+?^${}()|[\]\\]/</span>g, <span style="color: #98be65;">"\\$&"</span>)</code>: add a backslash to any special character in the query; <code>$&</code> is a special pattern used in Javascript’s <code class="src src-js">replacement</code> method.</li>
</ul>
</div>
</div>
</div>
<div class="taglist"><a href="https://chenyo.me/tags.html">Tags</a>: <a href="https://chenyo.me/tag-web.html">web</a> <a href="https://chenyo.me/tag-app.html">app</a> </div><div id="archive">
<a href="https://chenyo.me/archive.html">Other posts</a>
</div>
</div>
<div id="postamble" class="status"><div id="search-results"></div>
<footer>
<div class="footer-content">
<div class="footer-left">
<p>© 2024 chenyo. Some rights reserved.</p>
<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">
<img alt="Creative Commons License" style="border-width: 0"
src="https://i.creativecommons.org/l/by-nc/4.0/88x31.png"/>
</a>
</div>
<div class="social-links">
<a href="https://t.me/chenyo17" target="_blank" rel="noopener noreferrer">
<i class="fab fa-telegram"></i>
</a>
<a href="https://github.com/chenyo-17" target="_blank" rel="noopener noreferrer">
<i class="fab fa-github"></i>
</a>
</div>
</footer></div>
</body>
</html>