Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

233
LINES

< > BotCompany Repo | #1022824 // Blog Bot with chat bot [dev.]

JavaX module (desktop) [tags: butter use-pretranspiled] - homepage

Download Jar. Libraryless. Click here for Pure Java version (5448L/41K).

1  
!7
2  
3  
static new ThreadLocal<Bool> youtubeOff;
4  
5  
static int perPage = 20;
6  
7  
sS rawSelfLink(S uri) { ret "/blog" + addSlashPrefix(uri); }
8  
9  
html {
10  
  S vis = registerVisitor();
11  
  
12  
  S domain = domain();
13  
  print("domain: " + domain);
14  
  
15  
  if (swic(domain, "javax.")) {
16  
    pcall {
17  
      O result = callHtmlMethod2(getBot(#1020398), uri, params);
18  
      print("Result: " + className(result));
19  
      ret result;
20  
    }
21  
  }
22  
  
23  
  /*if (startsWith(uri, "/.well-known/pki-validation/"))
24  
    ret subBot_serveText(loadTextFile(userDir("validation.txt")));*/
25  
26  
  tempSetThreadLocal(youtubeOff, eq("1", params.get('youtubeOff))
27  
    || eqOneOf(params.get('youtube), "0", "off", "no"));
28  
  O[] linkStyle = litobjectarray("style", "color: inherit; text-decoration: underline");
29  
  
30  
  uri = dropPrefix("/", uri);
31  
  int page = startsWithDigit(uri) ? parseFirstInt(uri) : 1;
32  
  
33  
  LS allPosts = ll(
34  
    imagePost("2019/04/04", "Whenever my language bores me",
35  
    #1101627, "40%",
36  
    p("...I shorten it. Let's say I want to make a big input field with full persistence and switchable font size (like you see on the right). Then I write " + ahref("http://tinybrain.de/1022742", "this") + ":")
37  
+ [[<pre style="clear: both"><span title="compact module (sharing common code)" style="border-bottom: dotted 1px">cmodule</span> BigInput {
38  
  <span title="short for: String" style="border-bottom: dotted 1px">S</span> text; // auto-persisted string field
39  
  <span title="A field that can be changed through the module's popup menu" style="border-bottom: dotted 1px">switchable</span> int fontSize = 40;
40  
  <span title="short definition of the visualize() function" style="border-bottom: dotted 1px">visual</span> <a title="setFontSize" style="text-decoration: none; color: black; border-bottom: dotted 1px" href="http://tinybrain.de:8080/tb/show-snippet.php?id=1007197">setFontSize</a>(fontSize, <a title="dm_textArea - synonym of dm_fieldTextArea" style="text-decoration: none; color: black; border-bottom: dotted 1px" href="http://tinybrain.de:8080/tb/show-snippet.php?id=1021496">dm_textArea</a>(<span title="string constant, &#34;text&#34;" style="border-bottom: dotted 1px">'text</span>));
41  
}</pre>]]
42  
    + p("(I just created the 2 new JavaX syntax constructs " + ahref("http://tinybrain.de/1022743", "'switchable'") + " and " + ahref("http://tinybrain.de/1022746", "'visual'") + " in like 10 minutes. Hover over the source code for more info.) &mdash;" + ahref("http://botcompany.de/1004590/raw/1101628", "Automatic popup menu."))
43  
    ),
44  
    
45  
 imagePost("2018/06/16", "New Look&amp;Feel",
46  
                  #1016391, "30%",
47  
                  p([[Pretty, isn't it. Look&amp;Feel is called ]] + ahref("http://jtattoo.net", "JTattoo") + [[.]]) + p([[Image was made with the automatic screenshot module on a very old Windows 7 machine where my OS runs flawlessly.]]), left := true)
48  
                
49  
                , textPost("2018/06/15", "Fixing the last memory leaks in Java 10", [[
50  
                <p>I submitted this <a href="https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8204963">bug report</a> to Oracle, and I'm making
51  
                super-fancy functions like <a href="http://tinybrain.de/1016334">cleanDefunctACCsInAllThreads</a> that automatically fix
52  
                memory leaks other Java programmers have never heard of.</p>
53  
                <p>We will sail memory leak-free! :)</p>
54  
                ]]) + [[
55  
56  
                <!-- A single blog post -->
57  
                <section class="post">
58  
                    <header class="post-header">
59  
                        <img width="48" height="48" title="Stefan Reich's avatar" class="post-avatar" src="]] + snippetImgLink(#1101324) + [[">
60  
61  
                        <h2 class="post-title">New Module: YouTube Downloader</h2>
62  
63  
                        <p class="post-meta">
64  
                            By <a href="mailto:info@botcompany.de" class="post-author">Stefan Reich</a> @ 2018/06/14
65  
                        </p>
66  
                    </header>
67  
                    
68  
                    <div class="post-description" style="clear: both">
69  
                        <div style="float: right; width: 50%">
70  
                            <a href="https://botcompany.de/1004590/raw/1101311">
71  
                                <img title=""
72  
                                     class="pure-img-responsive"
73  
                                     src="https://botcompany.de/1004590/raw/1101311" style="width: 100%">
74  
                            </a>
75  
                        </div>
76  
                            
77  
                        <p>
78  
                            Today we launched <b>bla bla bla</b>.
79  
                        </p>
80  
                        <p>&nbsp;</p>
81  
                        <p>(No, seriously&mdash;we actually did. There is an awesome YouTube downloader in my <a href="http://exe.tinybrain.de/">operating system</a>. I'm just too lazy to write.)</p>
82  
                        <p>Now I need an awesome screenshot module and an awesome auto-upload-to-blog module.</p>
83  
                    </div>
84  
                </section>
85  
  ]]); // end of posts
86  
  
87  
  LS posts = subList(allPosts, (page-1)*perPage, page*perPage);
88  
  bool hasPrev = page > 1, hasNext = l(allPosts) > page*perPage;
89  
  
90  
  S nav = !hasNext && !hasPrev ? "" 
91  
    : hsection(joinNempties(" | ", 
92  
      hasPrev ? ahref(rawSelfLink(str(page-1)), "Last page") : "",
93  
      ahref("http://javax.botcompany.de/1020398/raw/contact", "Imprint"),
94  
      hasNext ? ahref(rawSelfLink(str(page+1)), "Next page") : ""),
95  
    class := "post", style := "text-align: right");
96  
    
97  
  S html = [[
98  
<!doctype html>
99  
<html lang="en">
100  
<head>
101  
    <meta charset="utf-8">
102  
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
103  
    <title>BotCompany.de</title>
104  
    
105  
    <link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" crossorigin="anonymous">
106  
    
107  
    <link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/grids-responsive-min.css">
108  
    <link rel="stylesheet" href="css/layouts/blog.css">
109  
</head>
110  
]] + hcss(loadSnippet_cached(#1008309))
111  
+ [[<body>]] + [[<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/cookie-bar/cookiebar-latest.min.js?tracking=1&always=1"></script>]] + [[
112  
113  
<div id="layout" class="pure-g">
114  
    <div class="sidebar pure-u-1 pure-u-md-1-4">
115  
        <div class="header">
116  
            <h1 class="brand-title"><a href="https://www.BotCompany.de">Bot]] + html_invisibleSpace() + [[Company</a></h1>
117  
            <h2 class="brand-tagline">English &amp; German Chat Bots</h2>
118  
119  
            <nav class="nav">
120  
                ]] + tag('ul,
121  
                    li(a("JAVAX", class := "pure-button", href := "http://javax.botcompany.de"), class := "nav-item")
122  
                + " " +
123  
                  li(a("GERMAN DEMO BOT", class := "pure-button", href := "http://www.web-woody-lab.de/", target := "_blank"), class := "nav-item")
124  
                + " " +
125  
                    li(a("DISCORD GROUP", class := "pure-button", href := "https://discordapp.com/invite/SEAjPqk", target := "_blank"), class := "nav-item")
126  
127  
                + " " +
128  
                   li(a("Download Windows", class := "pure-button", href := "https://www.botcompany.de/files/1400170/Stefans%20OS%20Installer.exe"), class := "nav-item")
129  
                + " " +
130  
                   + li(a("Download Mac/Linux", title := "Install Java first (from java.com)", class := "pure-button", href := "https://www.botcompany.de/files/1400169/Stefans%20OS.jar"), class := "nav-item")
131  
            
132  
                + " " +
133  
                      li(a("Videos", class := "pure-button", href := "http://youtube.tinybrain.de/"), class := "nav-item")
134  
                    //, class := "nav-list")
135  
                  + " " + //tag('ul,
136  
                      li(a("Meetings", class := "pure-button", target := "_blank", href := "http://aimeetup.tinybrain.de/"), class := "nav-item")
137  
                    //, class := "nav-list")
138  
                  + " " + //tag('ul,
139  
                      li(a("Slides", class := "pure-button", target := "_blank", href := "https://slides.com/stefanreich"), class := "nav-item")
140  
                    , class := "nav-list")
141  
                + [[
142  
            </nav>
143  
            
144  
            <p>&nbsp;</p>
145  
            <p><a style="text-decoration: none; color: white" href="https://www.botcompany.de:8443/1013826/raw"><b>Stefan's OS</b></a><br> is an inspiring Java program you can <a style="text-decoration: underline; color: white" href="https://www.botcompany.de:8443/1013826/raw">try out</a> in Windows, Mac OS or Linux.</p>
146  
            
147  
            ]] + p("&nbsp;") + youtubi("jt8j8llwBa8", 150)             
148  
            + "<br>"
149  
            + small("(good music)") +  [[
150  
        </div>
151  
    </div>
152  
153  
    <div class="content pure-u-1 pure-u-md-3-4">
154  
        <div>
155  
            <div class="posts">
156  
                <!--<h1 class="content-subhead">Recent News</h1>-->
157  
                ]]
158  
                
159  
                + hcss([[ pre { margin-left: 20px; font-weight: bold; } ]])
160  
                + nav
161  
                  
162  
                + lines(posts)
163  
                
164  
                + nav
165  
166  
                + [[
167  
                
168  
            </div>
169  
170  
            <div class="footer">
171  
                <div class="pure-menu pure-menu-horizontal">
172  
                    <ul>
173  
                        <li class="pure-menu-item" id="visitors"></li>
174  
                        <li class="pure-menu-item"><a href="https://www.botcompany.de:8443/1013826/raw" class="pure-menu-link">More</a></li>
175  
                        <li class="pure-menu-item"><a href="http://youtube.tinybrain.de/" class="pure-menu-link">YouTube</a></li>
176  
                        <li class="pure-menu-item"><a href="http://javax.botcompany.de/1020398/raw/contact" class="pure-menu-link">Impressum</a></li>
177  
                    </ul>
178  
                </div>
179  
            </div>
180  
        </div>
181  
    </div>
182  
</div>
183  
184  
</body>
185  
</html>
186  
]];
187  
188  
  ret html.replace("\"css/layouts/blog.css\"", htmlQuote(rawSnippetURL(#1016322, "text/css")))
189  
  .replaceFirst(regexpQuote("<body>"), "<body>" + hSilentComputatorWithFlag("homepage"));
190  
}
191  
192  
sS textPost(S date, S title, S text) {
193  
  ret invtag('section, class := "post", style := "clear: both",
194  
    invtag('header, class := "post-header",
195  
      invtag('img, width := 48, height := 48,
196  
        title := "Stefan Reich's avatar",
197  
        class := "post-avatar",
198  
        src := snippetImgLink(#1101324))
199  
      + [[
200  
      <h2 class="post-title">]] + title + [[</h2>
201  
202  
                        <p class="post-meta">
203  
                            By <a href="mailto:info@botcompany.de" class="post-author">Stefan Reich</a> @ ]] + date + [[
204  
                        </p>
205  
]]) + [[
206  
                    <div class="post-description">
207  
                    ]] + text + [[
208  
                    </div>]]);
209  
}
210  
211  
sS imagePost(S date, S title, S imageID, S width, S text, O... opt) {
212  
  bool left = optParam(opt, 'left, false);
213  
  S picLink = stringParam(opt, 'picLink);
214  
  ret textPost(date, title, 
215  
    invtag('div, style := "float: " + (left ? "left" : "right") + "; width: " + width + "; margin-bottom: 30px; margin-" + (left ? "right" : "left") + ": 30px;", ahref(or2(picLink, snippetImageLink(imageID)),
216  
    invTag('img, title := "",
217  
      class := "pure-img-responsive",
218  
      src := snippetImageLink(imageID),
219  
      style := "width: 100%")))
220  
  + text);
221  
}
222  
223  
sS youtubi(S url) {
224  
  ret isTrue(youtubeOff!) ? "" : youtubeEmbed_newer(url);
225  
}
226  
227  
sS youtubi(S url, int width) {
228  
  ret isTrue(youtubeOff!) ? "" : youtubeEmbed_newer(url, width);
229  
}
230  
231  
sS youtubi(S url, int width, int height) {
232  
  ret isTrue(youtubeOff!) ? "" : youtubeEmbed_newer(url, width, height);
233  
}

Author comment

Began life as a copy of #1016323

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022824
Snippet name: Blog Bot with chat bot [dev.]
Eternal ID of this version: #1022824/2
Text MD5: d0c9ed5b3bf9771370bf1de8ce8ede47
Transpilation MD5: 43dc7e4e66ab77bed8a31b5aa6308ec5
Author: stefan
Category: javax / html
Type: JavaX module (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-09 20:30:20
Source code size: 11859 bytes / 233 lines
Pitched / IR pitched: No / No
Views / Downloads: 206 / 1016
Version history: 1 change(s)
Referenced in: [show references]