-
Notifications
You must be signed in to change notification settings - Fork 1
/
feed.xml
1465 lines (1367 loc) · 71.7 KB
/
feed.xml
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Nodejs Dersleri</title>
<atom:link href="http://nodejs-dersleri.github.io/feed.xml" rel="self" type="application/rss+xml"></atom:link>
<link>http://nodejs-dersleri.github.io</link>
<description>NODEJS İÇİN TÜRKÇE KAYNAK, NOTLAR, ÖRNEK UYGULAMALAR</description>
<pubDate>Sun, 13 Dec 2015 00:30:00 +0200</pubDate>
<generator>Wintersmith - https://github.com/jnordberg/wintersmith</generator>
<language>en</language>
<item>
<title>Npm modül yapımı 2</title>
<link>http://nodejs-dersleri.github.io/articles/npm-modul-yapimi-2/</link>
<pubDate>Sun, 13 Dec 2015 00:30:00 +0200</pubDate>
<guid isPermaLink="true">http://nodejs-dersleri.github.io/articles/npm-modul-yapimi-2/</guid>
<author></author>
<description><p>Yapmış olduğumuz modülü npm’e register edip semantik versiyonlamaya göz atacağız.
Semantik versiyonlama hakkında daha fazla bilgiye <a href="http://semver.org">buradan</a> ulaşabilirsiniz.</p>
<hr>
<p><img src="/articles/npm-modul-yapimi-2/npm-modul-yapimi-2.png" alt="modul info"></p>
<h3 id="npm-register">Npm Register</h3>
<p>Öncelikle kullanıcı bilgilerimizi <code>npm adduser</code> ile ekliyoruz.</p>
<pre><code>⏣ npm adduser
Username: arifcakiroglu
Password:
Email: (this IS public) cakirogluarif@gmail.com
</code></pre><p><code>npm set</code>ile bilgilerinizi npmrc dosyasına ekleyebilirsiniz. Bilgilerinize <code>~/.npmrc</code> dosyasından ulaşabilirsiniz.</p>
<pre><code>npm set init.author.name &quot;Arif Cakiroglu&quot;
npm set init.author.email &quot;cakirogluarif@gmail.com&quot;
npm set init.author.url &quot;http://nodejs-dersleri.github.io&quot;
</code></pre><p>Daha sonra oluşturduğumuz modül dizinine gidip <code>npm publish</code> ile kayıt işlemine başlıyoruz.</p>
<pre><code>⏣ npm publish
+ guidify@0.1.0
</code></pre><h4 id="versiyonlama">Versiyonlama</h4>
<p>Eğer versiyon değişikliği yapmadan tekrar göndermeye çalışırsak aşağıdaki gibi bir hata ile karşılaşırız.</p>
<pre><code>npm ERR! publish Failed PUT 403
npm ERR! Darwin 15.0.0
npm ERR! argv &quot;/usr/local/bin/node&quot; &quot;/usr/local/bin/npm&quot; &quot;publish&quot;
npm ERR! node v5.0.0
npm ERR! npm v3.3.6
npm ERR! code E403
npm ERR! &quot;You cannot publish over the previously published version 0.1.0.&quot; : guidify
</code></pre><p>Versiyon güncelleme yapıp denediğimizde yeni versiyonumuz npm’e ulaşmış oluyor.</p>
<pre><code>⏣ npm publish
+ guidify@0.1.1
</code></pre><p><strong>Beta versiyonlamak</strong> için de <code>-beta</code> takısını kullanabilirsiniz. Bu, modülünüzün latest versiyonu olarak kabul edilmeyecek ve modülünüz <code>npm i -S guidify</code>diye çağırıldığında en son stable versiyonu inecektir. Eğer beta sürümünü kullanmak isterseniz <code>npm i -S guidify@beta</code> olarak indirebilirsiniz.</p>
<blockquote>
<p>Not: Beta versiyonu çıkarken <code>npm publish --tag beta</code> publish işlemini beta olarak tagliyoruz.</p>
</blockquote>
<pre><code>⏣ npm publish --tag beta
+ guidify@1.1.0-beta.0
npm i -S guidify@beta
└── guidify@1.1.0-beta.0
</code></pre><p><code>npm info</code> ile modülünüzün bilgilerine ulaşabilirsiniz. Aşağıda gördüğünüz gibi <code>&#39;dist-tags&#39;: { latest: &#39;1.1.1&#39;, beta: &#39;1.1.1-beta.0&#39; }</code> dist-tags kısmına beta versiyonunu ekledi.</p>
<pre><code>{ name: &#39;guidify&#39;,
time:
{ modified: &#39;2015-12-13T12:25:46.912Z&#39;,
created: &#39;2015-12-13T11:08:34.780Z&#39;,
&#39;0.1.0&#39;: &#39;2015-12-13T11:08:34.780Z&#39;,
&#39;0.1.1&#39;: &#39;2015-12-13T11:41:04.164Z&#39;,
&#39;1.0.1&#39;: &#39;2015-12-13T11:59:07.267Z&#39;,
&#39;1.1.0&#39;: &#39;2015-12-13T12:01:49.774Z&#39;,
&#39;1.1.0-beta.0&#39;: &#39;2015-12-13T12:02:47.048Z&#39;,
&#39;1.1.1&#39;: &#39;2015-12-13T12:25:08.334Z&#39;,
&#39;1.1.1-beta.0&#39;: &#39;2015-12-13T12:25:46.912Z&#39; },
maintainers: [ &#39;arifcakiroglu &lt;cakirogluarif@gmail.com&gt;&#39; ],
&#39;dist-tags&#39;: { latest: &#39;1.1.1&#39;, beta: &#39;1.1.1-beta.0&#39; },
description: &#39;Globally unique identifier&#39;,
versions: [ &#39;1.1.0&#39;, &#39;1.1.1&#39; ],
homepage: &#39;https://github.com/arifcakiroglu/guidify#readme&#39;,
keywords: [ &#39;unique&#39;, &#39;guid&#39;, &#39;guidify&#39; ],
repository:
{ type: &#39;git&#39;,
url: &#39;git+https://github.com/arifcakiroglu/guidify.git&#39; },
author: &#39;Arif Cakiroglu &lt;cakirogluarif@gmail.com&gt;&#39;,
bugs: { url: &#39;https://github.com/arifcakiroglu/guidify/issues&#39; },
license: &#39;MIT&#39;,
readmeFilename: &#39;README.md&#39;,
version: &#39;1.1.1&#39;,
main: &#39;index.js&#39;,
scripts: { test: &#39;mocha -R spec -u tdd tests/*.js&#39; },
devDependencies: { mocha: &#39;~1.14.0&#39; },
gitHead: &#39;8bae71a00fdb58a085346f14e3882cd6f6dad7b8&#39;,
dist:
{ shasum: &#39;6e5fc5382effeab16753c4eedad0c55ddb28f072&#39;,
tarball: &#39;http://registry.npmjs.org/guidify/-/guidify-1.1.1.tgz&#39; },
directories: {} }
</code></pre><h3 id="semantik-versiyonlamak">Semantik versiyonlamak</h3>
<p>Örnek kod:</p>
<pre><code>test = {
init: function(){
this.mesasge = &#39;howoryu :)&#39;
return this;
},
get: function(){
console.warn(this.message;
}
}
</code></pre><p><strong>1</strong>.0.1 <br>
^ MAJOR version: Uygulamanızın kullanıldığı yerlerde problem yaratabilecek değişikliklerin yapıldığı, genel değişikliklerin versiyonlanması için kullanılır.</p>
<p> Yukarıdaki kod parçaçığı üzerinden gidecek olursak örneğin:</p>
<p> <code>get</code> methodunu <code>getMessage</code> diye değiştirdiğinizde versiyonlamada köklü bir değişiklik yapıyorsunuz demektir. Önceki kullanımda get olarak kullanılan method, versiyon güncelleme ile artık programı kullanılamaz hale getirecektir.</p>
<p> 1.<strong>0</strong>.1 <br>
—^ MINOR version: Uygulamanızın kullanımını kökten değiştirmeyecek ama yeni özellik olarak ekleyeceğiniz farklıklar için kullanılır.</p>
<p>Örneğin: <code>get</code> methodu gibi bir de <code>set</code>methodu eklediğimizi düşünelim. Bu aşamada kullanıcılar uygulamanızda artık yeni bir özelliğin geldiğini bileceklerdir.</p>
<pre><code>set: function(args){
this.message = args
}
</code></pre><p>1.0.<strong>1</strong> <br>
—–^ PATCH version: Uygulamanızda ki bug fixler için kullanılan kısım. yaptığınız herhangi bir problemi giderip versiyonlamanızı yapabilirsiniz.</p>
<pre><code>get: function(){
// console.warn(this.message;
console.warn(this.message);
}
</code></pre><p>Semantik versiyonlama hakkında daha fazla bilgiye <a href="http://semver.org">buradan</a> ulaşabilirsiniz.</p>
<p><strong>Sorularınız olursa yorum yapmaktan çekinmeyiniz efenim, saygılar.</strong></p>
<hr>
</description>
</item>
<item>
<title>Nodejs REPL(Read-Eval-Print-Loop)</title>
<link>http://nodejs-dersleri.github.io/articles/nodejs-read-eval-print-loop/</link>
<pubDate>Mon, 07 Dec 2015 02:30:00 +0200</pubDate>
<guid isPermaLink="true">http://nodejs-dersleri.github.io/articles/nodejs-read-eval-print-loop/</guid>
<author></author>
<description><h3 id="repl-nedir-">REPL nedir?</h3>
<p>Terminalden interaktif bir şekilde JavaScript çalıştırarak sonuçlarını görmeye yarar. Debug, test ya da bir şeyler denemek için kullanılabilir.</p>
<p>Hızlıca bazı kodları denemek istiyorsanız her defasında <code>npm init</code> ile bir proje yaratıp, bir index.js üzerinden çalışmaktansa terminalden sadece <code>node</code> yazarak Repl’e giriş yapmış oluyoruz.</p>
<hr>
<p><img src="/articles/nodejs-read-eval-print-loop/nodejs-repl.png" alt="nodejs-repl"></p>
<h4 id="matematik-i-lemleri">Matematik işlemleri</h4>
<pre><code>λ node
&gt; 6 * 2
12
&gt; 2 + 2
4
</code></pre><h4 id="de-i-ken-tan-mlar-">Değişken tanımları</h4>
<pre><code>&gt; var arr = [null, undefined, false]
undefined
&gt; arr
// sonuç:
[ null, undefined, false ]
&gt; arr.forEach(function(val) {
... console.log(val)
... });
// sonuç:
null
undefined
false
</code></pre><h4 id="repl-zellikleri">REPL özellikleri</h4>
<blockquote>
<p>_ altçizgi: en son çalıştırdığınız sorguyu işler</p>
</blockquote>
<pre><code>// değişkeni tanımladık
width = 3 + 5;
// altçizgi çıktı olarak işlemin sonucunu verdi
_
8
// sadece altçizgi yazarak işmele devam ediyoruz
&gt; _ * 2
16
&gt; a = [1,2,3]
[ 1, 2, 3 ]
&gt; _.length
3
</code></pre><blockquote>
<p>Multiline çalışmak</p>
</blockquote>
<p>Yazıma başladığınızda göreceksinizki enter yaptığınızda yazdığınız kodu işleme alacaktır.</p>
<pre><code>console.warn = function( e ) { process.stdout.write( e ) }
[Function]
</code></pre><p>Eğer yazacağınız fonksiyon fazla satır tutacaksa süslü parantezden sonra enter yaparsanız bir alt satıra geçecektir. Süslü parantezi kapadıktan sonra enter yaparsanız kodu işleme alacaktır.</p>
<pre><code>var chalk = require(&#39;chalk&#39;);
undefined
console.warn = function( e ) {
...process.stdout.write( chalk.red(e) )
...process.exit(1)
...};
</code></pre><p>Not: Eğer multiline fonksiyon yazarken hatalı bir işlem yaparsanız <code>kntrl+c</code> yaparsanız çıkış yapacaktır. <code>.clear</code> ya da <code>.break</code> yazarak da çıkış yapabilirsiniz.</p>
<h4 id="repl-komutlar-">REPL komutları</h4>
<p><br></p>
<p><strong><code>.help</code></strong> komutları unuttuysanız hızlıca göz atabilirsiniz.</p>
<pre><code>&gt; .help
break Sometimes you get stuck, this gets you out
clear Alias for .break
exit Exit the repl
help Show repl options
load Load JS from a file into the REPL session
save Save all evaluated commands in this REPL session to a file
</code></pre><p><strong><code>.break, .clear</code></strong> Multiline yazımda satırdan çıkmak ve işlemi iptal etmek için kullanılır.</p>
<p><strong><code>.exit</code></strong> REPL’den çıkış yapar.</p>
<p><strong><code>.save main.js</code></strong> REPL’den girmiş olduğunuz verileri saklamak isterseniz kullanabilirsiniz. main.js kaydedeceğimiz dosyanın ismi. İstediğiniz isimde kaydedebilirsiniz.</p>
<p><strong><code>.load main.js</code></strong> Path belirtilerek REPL dosyasını tekrar çağırabilir ve kaldığınız yerden devam edebilirsiniz.</p>
<p><strong><code>kntrl + c</code></strong> .break ile aynı işlemi yapar, içinde bulunulan fonksiyondan çıkış yapar.</p>
<p><strong><code>kntrl + c (iki kere)</code></strong> REPL’den çıkmaya yarar.</p>
<p><strong><code>tab</code></strong> Yazdığınız fonksiyon ve değişkenleri, global fonksiyonları görebilirsiniz. History olarak da tanımlayabiliriz.</p>
<blockquote>
<p>tab çıktı örneği</p>
</blockquote>
<pre><code>Map Promise
Set Symbol
Uint16Array Uint32Array
Uint8Array Uint8ClampedArray
WeakMap WeakSet
dir a
assert b
buffer child_process
clearImmediate clearInterval
</code></pre><h4 id="faydal-eyler">Faydalı şeyler</h4>
<p>REPL içindeyken ekranı temizlemek isterseniz <code>kntrl + cmd + L</code> yaparsanız ekranınız mis gibi olur yazmaya devam edebilirsiniz. <code>clear</code> komutuyla aynı işe yarar farkı REPL içerisinde clear ya da tanımlı herhangi bir Alias yazarsanız hata alırsınız. Bunun yerine kısayol ile hızlıca temizlik yapabilirsiniz ;)</p>
<h4 id="okudu-unuz-i-in-te-ekk-r-ederim">Okuduğunuz için teşekkür ederim</h4>
<hr>
</description>
</item>
<item>
<title>Phantomjs ile responsive ekran görüntüsü alma - 2</title>
<link>http://nodejs-dersleri.github.io/articles/phantomjs-ile-responsive-ekran-goruntusu-alma-2/</link>
<pubDate>Mon, 23 Nov 2015 23:00:00 +0200</pubDate>
<guid isPermaLink="true">http://nodejs-dersleri.github.io/articles/phantomjs-ile-responsive-ekran-goruntusu-alma-2/</guid>
<author></author>
<description><p>İlk yazımızda ekran görüntüsü almış ve kaydetmiştik, bu yazımızda ise farklı çözünürlüklerde birden çok ekran görüntüsü kaydedeceğiz, bunun yanı sıra script’imize cli’dan gelen paremetrelere farklı davranışlar sergileteceğiz.</p>
<hr>
<h3 id="rssg-js">rssg.js</h3>
<p>Dosyamızın son hali bu şekildeydi, bunun üzerinden devam edeceğiz.</p>
<pre><code>var args = require(&#39;system&#39;).args;
var fs = require(&#39;fs&#39;);
var page = new WebPage();
if ( 1 === args.length ) {
console.log(&#39;Url addresi girmediniz&#39;);
phantom.exit();
}
var urlAddress = args[1].toLowerCase();
var viewports = [
{
width : 1200,
height : 800
},
{
width : 1024,
height : 768
},
{
width : 768,
height : 1024
},
{
width : 480,
height : 640
},
{
width : 320,
height : 480
}
];
page.open(urlAddress, function (status) {
if ( &#39;success&#39; !== status ) {
console.log(&#39;Adrese bağlanılamadı.&#39;);
} else {
var folder = urlToDir(urlAddress);
page.viewportSize = viewports[0];
var output = folder + &quot;/&quot; + getFileName();
console.log(&#39;Saving &#39; + output);
page.render(output);
}
phantom.exit();
});
function urlToDir(url) {
var dir = url
.replace(/^(http|https):\/\//, &#39;&#39;)
.replace(/\/$/, &#39;&#39;);
if ( !fs.makeTree(dir) ) {
console.log(&#39;&quot;&#39; + dir + &#39;&quot; oluşturulamadı.&#39;);
phantom.exit();
}
console.log(&#39;&quot;&#39; + dir + &#39;&quot; oluşturuldu.&#39;);
return dir;
}
function getFileName() {
var d = new Date();
var date = [
d.getUTCFullYear(),
d.getUTCMonth() + 1,
d.getUTCDate()
];
var time = [
d.getHours() &lt;= 9 ? &#39;0&#39; + d.getHours() : d.getHours(),
d.getMinutes() &lt;= 9 ? &#39;0&#39; + d.getMinutes() : d.getMinutes(),
d.getSeconds() &lt;= 9 ? &#39;0&#39; + d.getSeconds() : d.getSeconds(),
d.getMilliseconds()
];
return date.join(&#39;-&#39;) + &#39;_&#39; + time.join(&#39;-&#39;) + &quot;.png&quot;;
}
</code></pre><h3 id="-kt-format-">Çıktı formatı</h3>
<p>şimdide paremetre ile dosyayı kaydedeceğimiz formatı parametre olarak alalım.</p>
<p>urlAddress değişkenimizin altına hemen şu kodu yapıştıralım.</p>
<pre><code>var ext = &#39;.&#39; + (args[2] || &#39;png&#39;).toLowerCase();
</code></pre><p>buraki kodu açıklamak gerekirse parantezleri kullanarak işlem önceliğini belirledik, <strong>args[2]</strong> parametresi varsa kullan yoksa <strong>png</strong> kullan dedik daha sonra <strong>toLowerCase</strong> fonskiyonu ile hepsini kucuk yazi haline getirdik en son <strong>.</strong> işareti ile birleştirdik.</p>
<h4 id="getfilename">getFileName</h4>
<p>şimdi burdada ufak bir düzenleme yapalım</p>
<pre><code>return date.join(&#39;-&#39;) + &#39;_&#39; + time.join(&#39;-&#39;) + &quot;.png&quot;;
</code></pre><p>satırını </p>
<pre><code>return date.join(&#39;-&#39;) + &#39;_&#39; + time.join(&#39;-&#39;) + ext;
</code></pre><p>ile değiştirelim</p>
<pre><code>function getFileName() {
var d = new Date();
var date = [
d.getUTCFullYear(),
d.getUTCMonth() + 1,
d.getUTCDate()
];
var time = [
d.getHours() &lt;= 9 ? &#39;0&#39; + d.getHours() : d.getHours(),
d.getMinutes() &lt;= 9 ? &#39;0&#39; + d.getMinutes() : d.getMinutes(),
d.getSeconds() &lt;= 9 ? &#39;0&#39; + d.getSeconds() : d.getSeconds(),
d.getMilliseconds()
];
return date.join(&#39;-&#39;) + &#39;_&#39; + time.join(&#39;-&#39;) + ext;
}
</code></pre><pre><code>phantomjs rssg.js https://nodejs-dersleri.github.io/ pdf
</code></pre><p><img src="/articles/phantomjs-ile-responsive-ekran-goruntusu-alma-2/pdf.png" alt="pdf"></p>
<p>hangi formatlarda çıktı alabileceğimizi bir önceki yazımızda listemiştik.</p>
<h3 id="g-r-nt-y-k-rpma">Görüntüyü kırpma</h3>
<p>şimdide az önce eklediğimiz <strong>ext</strong> değişkenin altına şu kodu ekleyelim</p>
<pre><code>var clipping = args[3] || false;
</code></pre><h4 id="getfilename">getFileName</h4>
<p>şimdide fonksiyonumuzda biraz değişiklik yapalım</p>
<pre><code>function getFileName(viewport) {
var d = new Date();
var date = [
d.getUTCFullYear(),
d.getUTCMonth() + 1,
d.getUTCDate()
];
var time = [
d.getHours() &lt;= 9 ? &#39;0&#39; + d.getHours() : d.getHours(),
d.getMinutes() &lt;= 9 ? &#39;0&#39; + d.getMinutes() : d.getMinutes(),
d.getSeconds() &lt;= 9 ? &#39;0&#39; + d.getSeconds() : d.getSeconds(),
d.getMilliseconds()
];
var resolution = viewport.width + (clipping ? &quot;x&quot; + viewport.height : &#39;&#39;);
return date.join(&#39;-&#39;) + &#39;_&#39; + time.join(&#39;-&#39;) + &quot;_&quot; + resolution + ext;
}
</code></pre><p>yaptığımız değişiklikleri hızlıca özetleyelim, fonksiyonumuz artık bir viewport parametre alıyor ve <strong>resolution</strong> adında yeni bir değişkene sahip bu değişkene ise gelen viewport objesinin width değerini ve clipping varsa height degerini basıyor.</p>
<h4 id="ba-lant-kodu">bağlantı kodu</h4>
<pre><code>page.open(urlAddress, function (status) {
if ( &#39;success&#39; !== status ) {
console.log(&#39;Adrese bağlanılamadı.&#39;);
} else {
var folder = urlToDir(urlAddress);
if ( clipping ) {
page.clipRect = viewports[0];
}
page.viewportSize = viewports[0];
var output = folder + &quot;/&quot; + getFileName(viewports[0]);
console.log(&#39;Saving &#39; + output);
page.render(output);
}
phantom.exit();
});
</code></pre><p>Eğer clipping değişkeni false değilse <strong>page.clipRect = viewports[0];</strong> komutunu aktif ediyoruz bu bizim görüntüyü kırpma kodumuz, ve getFileName fonksiyonumuza viewport parametresini gönderdik <strong>getFileName(viewports[0])</strong> </p>
<pre><code>phantomjs rssg.js https://nodejs-dersleri.github.io/ png
</code></pre><pre><code>phantomjs rssg.js https://nodejs-dersleri.github.io/ png true
</code></pre><p>bu 2 komutunda sorunsuz çalışması gerekiyor.( eğer çalışmaz yazının devamında mevcut kodlarımızı vereceğim karşılaştırma yapabilirsiniz)
<img src="/articles/phantomjs-ile-responsive-ekran-goruntusu-alma-2/clipping.png" alt="clipping"></p>
<h3 id="rssg-js">rssg.js</h3>
<pre><code>var args = require(&#39;system&#39;).args;
var fs = require(&#39;fs&#39;);
var page = new WebPage();
if ( 1 === args.length ) {
console.log(&#39;Url addresi girmediniz&#39;);
phantom.exit();
}
var urlAddress = args[1].toLowerCase();
var ext = &#39;.&#39; + (args[2] || &#39;png&#39;).toLowerCase();
var clipping = args[3] || false;
var viewports = [
{
width : 1200,
height : 800
},
{
width : 1024,
height : 768
},
{
width : 768,
height : 1024
},
{
width : 480,
height : 640
},
{
width : 320,
height : 480
}
];
page.open(urlAddress, function (status) {
if ( &#39;success&#39; !== status ) {
console.log(&#39;Adrese bağlanılamadı.&#39;);
} else {
var folder = urlToDir(urlAddress);
if ( clipping ) {
page.clipRect = viewports[0];
}
page.viewportSize = viewports[0];
var output = folder + &quot;/&quot; + getFileName(viewports[0]);
console.log(&#39;Saving &#39; + output);
page.render(output);
}
phantom.exit();
});
function urlToDir(url) {
var dir = url
.replace(/^(http|https):\/\//, &#39;&#39;)
.replace(/\/$/, &#39;&#39;);
if ( !fs.makeTree(dir) ) {
console.log(&#39;&quot;&#39; + dir + &#39;&quot; oluşturulamadı.&#39;);
phantom.exit();
}
console.log(&#39;&quot;&#39; + dir + &#39;&quot; oluşturuldu.&#39;);
return dir;
}
function getFileName(viewport) {
var d = new Date();
var date = [
d.getUTCFullYear(),
d.getUTCMonth() + 1,
d.getUTCDate()
];
var time = [
d.getHours() &lt;= 9 ? &#39;0&#39; + d.getHours() : d.getHours(),
d.getMinutes() &lt;= 9 ? &#39;0&#39; + d.getMinutes() : d.getMinutes(),
d.getSeconds() &lt;= 9 ? &#39;0&#39; + d.getSeconds() : d.getSeconds(),
d.getMilliseconds()
];
var resolution = viewport.width + (clipping ? &quot;x&quot; + viewport.height : &#39;&#39;);
return date.join(&#39;-&#39;) + &#39;_&#39; + time.join(&#39;-&#39;) + &quot;_&quot; + resolution + ext;
}
</code></pre><h3 id="t-m-z-n-rl-kler">Tüm çözünürlükler</h3>
<h4 id="ba-lant-fonksiyonumuzu-g-ncelleyelim">bağlantı fonksiyonumuzu güncelleyelim</h4>
<pre><code>page.open(urlAddress, function (status) {
if ( &#39;success&#39; !== status ) {
console.log(&#39;Adrese bağlanılamadı.&#39;);
} else {
var folder = urlToDir(urlAddress);
var key, output;
function render(n) {
if ( !!n ) {
key = n - 1;
page.viewportSize = viewports[key];
if ( clipping ) {
page.clipRect = viewports[key];
}
output = folder + &quot;/&quot; + getFileName(viewports[key]);
console.log(&#39;Saving &#39; + output);
page.render(output);
render(key);
}
}
render(viewports.length);
}
phantom.exit();
});
</code></pre><p>burada for ile tüm viewports dizisini dönebilirsiniz, ben recursive fonksiyon kullanmayi tercih ettim bunun nedeni bana göre işi biten bir sonraki işlemi tetiklemeli.</p>
<pre><code>phantomjs rssg.js https://nodejs-dersleri.github.io/ png true
</code></pre><p><img src="/articles/phantomjs-ile-responsive-ekran-goruntusu-alma-2/clipping.png" alt="clipping"></p>
<h3 id="rssg-js">rssg.js</h3>
<p>son olarak kodumuzun son hali.</p>
<pre><code>var args = require(&#39;system&#39;).args;
var fs = require(&#39;fs&#39;);
var page = new WebPage();
if ( 1 === args.length ) {
console.log(&#39;Url addresi girmediniz&#39;);
phantom.exit();
}
var urlAddress = args[1].toLowerCase();
var ext = &#39;.&#39; + (args[2] || &#39;png&#39;).toLowerCase();
var clipping = args[3] || false;
var viewports = [
{
width : 1200,
height : 800
},
{
width : 1024,
height : 768
},
{
width : 768,
height : 1024
},
{
width : 480,
height : 640
},
{
width : 320,
height : 480
}
];
page.open(urlAddress, function (status) {
if ( &#39;success&#39; !== status ) {
console.log(&#39;Adrese bağlanılamadı.&#39;);
} else {
var folder = urlToDir(urlAddress);
var key, output;
function render(n) {
if ( !!n ) {
key = n - 1;
page.viewportSize = viewports[key];
if ( clipping ) {
page.clipRect = viewports[key];
}
output = folder + &quot;/&quot; + getFileName(viewports[key]);
console.log(&#39;Saving &#39; + output);
page.render(output);
render(key);
}
}
render(viewports.length);
}
phantom.exit();
});
function urlToDir(url) {
var dir = url
.replace(/^(http|https):\/\//, &#39;&#39;)
.replace(/\/$/, &#39;&#39;);
if ( !fs.makeTree(dir) ) {
console.log(&#39;&quot;&#39; + dir + &#39;&quot; oluşturulamadı.&#39;);
phantom.exit();
}
console.log(&#39;&quot;&#39; + dir + &#39;&quot; oluşturuldu.&#39;);
return dir;
}
function getFileName(viewport) {
var d = new Date();
var date = [
d.getUTCFullYear(),
d.getUTCMonth() + 1,
d.getUTCDate()
];
var time = [
d.getHours() &lt;= 9 ? &#39;0&#39; + d.getHours() : d.getHours(),
d.getMinutes() &lt;= 9 ? &#39;0&#39; + d.getMinutes() : d.getMinutes(),
d.getSeconds() &lt;= 9 ? &#39;0&#39; + d.getSeconds() : d.getSeconds(),
d.getMilliseconds()
];
var resolution = viewport.width + (clipping ? &quot;x&quot; + viewport.height : &#39;&#39;);
return date.join(&#39;-&#39;) + &#39;_&#39; + time.join(&#39;-&#39;) + &quot;_&quot; + resolution + ext;
}
</code></pre><h3 id="son-olarak">son olarak</h3>
<p>İlk yazı biraz uzun sürdüğü için bu yazımızda mümkün olduğunca kısa tutarak devam etmek istedim, kimine göre ilk yazı sıkıcı ve uzun, kimine göre bu yazı yeterince açıklayacı olmayacak diye tahmin ediyorum.
Uzun lafın kısası umarım okuyan herkes için faydalı bir anlatım olmuştur.</p>
<hr>
</description>
</item>
<item>
<title>Phantomjs ile responsive ekran görüntüsü alma - 1</title>
<link>http://nodejs-dersleri.github.io/articles/phantomjs-ile-responsive-ekran-goruntusu-alma/</link>
<pubDate>Sun, 22 Nov 2015 23:00:00 +0200</pubDate>
<guid isPermaLink="true">http://nodejs-dersleri.github.io/articles/phantomjs-ile-responsive-ekran-goruntusu-alma/</guid>
<author></author>
<description><p>Phantomjs kullanarak cli üzerinden belli bir sayfanın farklı çözünürlüklerdeki görüntüsü kaydedeceğiz.</p>
<hr>
<h3 id="gereksinimler">Gereksinimler</h3>
<ul>
<li>Phantomjs</li>
</ul>
<p>Yazacağımız kodlar phantomjs üzerinden çalışacağı için phantomjs’e bağımlıdır, aşşağıdaki adresten phantomjs’i indirip kurabilirsiniz.</p>
<p><a href="http://phantomjs.org/download.html">http://phantomjs.org/download.html</a></p>
<h3 id="rssg-js">rssg.js</h3>
<p>Öncelikle kodlarımızı yazmak için bir dosya açmamız gerekiyor, ben responsive screen shot grabber’ın kısaltması olan <strong>rssg.js</strong> olarak açacağım anlatım boyuncada bunun üzerinden devam edeceğim.</p>
<h3 id="system-args">system.args</h3>
<pre><code>var args = require(&#39;system&#39;).args;
</code></pre><p>Sistem modülünün çeşitli özellikleri mevcut <a href="http://phantomjs.org/api/system/">http://phantomjs.org/api/system/</a> buradan bunlara erişebilirsiniz, bize bu anlatımda sadece <strong>args</strong> özelliği gerekli.</p>
<p>system.args özelliği javascriptten bildiğimiz arguments ile aynı görevi yapmakta, yani girilen her parametreyi bir dizi olarak bize döndürmektedir.</p>
<p>bir örnek ile pekiştiricek olursak;</p>
<pre><code>function test(){
return arguments;
}
var cevap = test(1,2,3)
</code></pre><p>cevap nesnesi bize geriye <strong>[1,2,3]</strong> döndürür, cevap[0] ise <strong>1</strong>;
system.arg’da aynen bu işi yapmakta, phantom js ile örneklendiricek olursak eğer;</p>
<pre><code>phantomjs rssg.js https://nodejs-dersleri.github.io/
</code></pre><p>komutu tetiklediğimizde args nesnemiz şu şekilde olacaktır;</p>
<p>[‘rssg.js’, ‘<a href="https://nodejs-dersleri.github.io/">https://nodejs-dersleri.github.io/</a>‘]</p>
<p>dipnot: cli’dan gelen her parametre string formatındadır.</p>
<h3 id="fs-filesystem-">fs (filesystem)</h3>
<pre><code>var fs = require(&#39;fs&#39;);
</code></pre><p>Adındanda anlaşılacağı gibi dosya sistemi api’ı, dosyalar ile ilgili birçok işlemi içinde barındıran mödül.
Mevcut olan tüm api listesine buradan ulaşabilirsiniz <a href="http://phantomjs.org/api/fs/">http://phantomjs.org/api/fs/</a></p>
<p>dipnot:kullanılabilir özelliklere yukarıda ki adresden bakınız node.js üzerindeki fs api’ı ile aynı değildir. </p>
<h3 id="webpage">Webpage</h3>
<p>phantomjs’in olmazsa olmazı diyebiliriz.
sayfalarımızı bu api sayesinde acip ekran görüntüsünü alacağız</p>
<pre><code>var page = new WebPage();
</code></pre><p>tüm api listesine buradan ulaşabilirsiniz <a href="http://phantomjs.org/api/webpage/">http://phantomjs.org/api/webpage/</a></p>
<h3 id="url-varm-">Url varmı ?</h3>
<pre><code>if ( 1 === args.length ) {
console.log(&#39;Url adresi girmediniz&#39;);
phantom.exit();
}
</code></pre><p>yukarıdaki kodu açıklayacak olursak;</p>
<ul>
<li>herşeyden önce if koşulu size biraz farklı gelmiş olabilir <strong>Yoda conditions</strong> jargonu diye geçer ve çeşitli avantajları vardır (ben henüz bir dezavantajını görmedim) bunları ilgili wikipedia sayfasından ve çeşitli kaynaklardan bulabilirsiniz <a href="https://en.wikipedia.org/wiki/Yoda_conditions">https://en.wikipedia.org/wiki/Yoda_conditions</a></li>
<li><strong>1 === args.length</strong>
unutmayın ilk parametre dosyamızın adı eğer length 1’e eşit ise args nesnem <strong>[‘rssg.js’]</strong> şeklindedir herhangi bir parametre girilmemiş, dolasıyla bağlanacak bir url adresimiz yok demektir.</li>
<li>eğer koşulumuz sağlanırsa <strong>phantom.exit();</strong> ile işlemleri sonlandırıyoruz.</li>
</ul>
<h3 id="url-address">url address</h3>
<pre><code>var urlAddress = args[1].toLowerCase();
</code></pre><p>Unutmayın gelen her parametre string (kullanıcı 1 değerini girmiş olsa bile string olarak geleceği için string mi diye kontrol etmemize gerek yok), dolasıyla string nesnesinin her özelliğini kullanabiliriz.
Daha sonra bu url adresini klasör oluştururken’de kullanacağız o yüzden düzenli bir yapı elde etmek için gelen adresi toLowerCase() ile tümünü küçük harflere çeviriyoruz.</p>
<h3 id="-z-n-rl-kler">çözünürlükler</h3>
<p>Hangi çözünürlüklerde çıktılar alacağımızı belirleyeceğimiz bir dizi yaratıyoruz.</p>
<pre><code>var viewports = [
{
width : 1200,
height : 800
},
{
width : 1024,
height : 768
},
{
width : 768,
height : 1024
},
{
width : 480,
height : 640
},
{
width : 320,
height : 480
}
];
</code></pre><h3 id="rssg-js">rssg.js</h3>
<p>karışıklıkların önüne geçmek için dosyamızın şuanki hali şu şekilde olmalı.</p>
<pre><code>var args = require(&#39;system&#39;).args;
var fs = require(&#39;fs&#39;);
var page = new WebPage();
if ( 1 === args.length ) {
console.log(&#39;Url adresi girmediniz&#39;);
phantom.exit();
}
var urlAddress = args[1].toLowerCase();
var viewports = [
{
width : 1200,
height : 800
},
{
width : 1024,
height : 768
},
{
width : 768,
height : 1024
},
{
width : 480,
height : 640
},
{
width : 320,
height : 480
}
];
</code></pre><h3 id="test-zaman-">Test Zamanı</h3>
<pre><code>page.open(urlAddress, function (status) {
if ( &#39;success&#39; !== status ) {
console.log(&#39;Adrese bağlanılamadı.&#39;);
} else {
console.log(urlAddress, &#39;bağlantı başarılı&#39;);
}
phantom.exit();
});
</code></pre><p>Bu kodu’da ekledikten sonra <strong>phantomjs rssg.js <a href="http://www.google.com">http://www.google.com</a></strong>
komutu ile terminalden kontrol ediyoruz
<img src="/articles/phantomjs-ile-responsive-ekran-goruntusu-alma/test.png" alt="test"></p>
<h3 id="klas-r-olu-tural-m">klasör oluşturalım</h3>
<p>ilk önce url adresini klasör adına dönüştürcek ve oluşturcak bir fonksiyon yazalım</p>
<pre><code>function urlToDir(url) {
var dir = url
.replace(/^(http|https):\/\/, &#39;&#39;)
.replace(/\/$/, &#39;&#39;);
if ( !fs.makeTree(dir) ) {
console.log(&#39;&quot;&#39; + dir + &#39;&quot; oluşturulamadı.&#39;);
phantom.exit();
}
console.log(&#39;&quot;&#39; + dir + &#39;&quot; oluşturuldu.&#39;);
return dir;
}
</code></pre><p>kısaca fonksiyonumuzu açıklayalım,</p>
<ul>
<li>fonksiyonumuz 1 parametre alıyor ve bunun url adresi olması bekleniyor</li>
<li>gelen url adresi regex kullanarak replace methodu yardımıyla temizleniyor ve <strong>dir</strong> değişkenine aktarılıyor.<ul>
<li>/^(http|https):\/\/ <strong>http://</strong> yada <strong>https://</strong> ile başyalanları demek anlamına geliyor</li>
<li>/\/$/ <strong>/</strong> ile bitenler anlamına geliyor</li>
</ul>
</li>
<li>fs.makeTree() fonksiyonu string alir ve boolean bir değer döner aldığı string paremetreye göre klasör oluşturur <a href="http://phantomjs.org/api/fs/method/make-tree.html">http://phantomjs.org/api/fs/method/make-tree.html</a><ul>
<li>if ( !fs.makeTree(dir) ) az önce oluşturduğumuz path i verdik eğer ki klasörü oluşturursa geriye true değerini dönecek bu bizim istediğimiz sonuç gelen sonuçu tersine ceviriyoruz true ise false, false ise true yapıyoruz. fonksiyonunun bize false donmesi durumunda if koşulu true olucak ve içeriye giricek.
bu durumda console’a klasör oluşturulamadı diyip phantomjs’den çıkış yapıyoruz.</li>
<li>eğer ki if koşulu gerçekleşmez ise geriye path’i (klasör yolunu) döndürüyoruz.</li>
</ul>
</li>
</ul>
<p>bağlantı kodunu güncelleyelim</p>
<pre><code>page.open(urlAddress, function (status) {
if ( &#39;success&#39; !== status ) {
console.log(&#39;Adrese bağlanılamadı.&#39;);
} else {
var folder = urlToDir(urlAddress);
}
phantom.exit();
});
</code></pre><pre><code>phantomjs rssg.js http://www.google.com
</code></pre><p><img src="/articles/phantomjs-ile-responsive-ekran-goruntusu-alma/klasor.png" alt="klasor"></p>
<p> ve dizinimizde klasör oluşmuş olması gerekiyor.</p>
<h3 id="dosya-ad-">dosya adı</h3>
<p>Aynı sayfa için birçok defa deneme yapılabileceği için benzersiz dosya isimleri oluşturmamız lazım ve aralarındaki farkları görmek açısından bence tarihe göre dosya isimlendirmesi yapmak mantıklı olur.</p>
<pre><code>function getFileName(viewport) {
var d = new Date();
var date = [
d.getUTCFullYear(),
d.getUTCMonth() + 1,
d.getUTCDate()
];
var time = [
d.getHours() &lt;= 9 ? &#39;0&#39; + d.getHours() : d.getHours(),
d.getMinutes() &lt;= 9 ? &#39;0&#39; + d.getMinutes() : d.getMinutes(),
d.getSeconds() &lt;= 9 ? &#39;0&#39; + d.getSeconds() : d.getSeconds(),
d.getMilliseconds()
];
return date.join(&#39;-&#39;) + &#39;_&#39; + time.join(&#39;-&#39;) + &quot;.png&quot;;
}
</code></pre><p>yukarıdaki kod’da çok fazla açıklanacak birşey yok aslında sadece sürekli <strong>+</strong> ile concat etmek yerine parçaları diziye atayıp <strong>-</strong> ile birleştiriyorum.</p>
<h3 id="ilk-ekran-g-r-nt-s-i-in-son-haz-rl-k">ilk ekran görüntüsü için son hazırlık</h3>
<p>bağlantı kodumuzu şu şekilde güncelleyelim</p>
<pre><code>page.open(urlAddress, function (status) {
if ( &#39;success&#39; !== status ) {
console.log(&#39;Adrese bağlanılamadı.&#39;);
} else {
var folder = urlToDir(urlAddress);
page.viewportSize = viewports[0];
var output = folder + &quot;/&quot; + getFileName();
console.log(&#39;Saving &#39; + output);
page.render(output);
}
phantom.exit();
});
</code></pre><p>Yeni gelen komutlarımızı tanıyalım webpage modülünün linkini yukarı belirtmiştim zaten, detaylı bakmak için yukarıda bağlantıyı kullanabilirsiniz.</p>
<ul>
<li><strong>page.viewportSize</strong> sayfa görünüm boyutunu ayarlamak için kullanılıyor. <a href="http://phantomjs.org/api/webpage/property/viewport-size.html">http://phantomjs.org/api/webpage/property/viewport-size.html</a></li>
<li><strong>page.render</strong> sayfayı kaydetmet için kullanılıyor çıktı formatları <a href="http://phantomjs.org/api/webpage/method/render.html">http://phantomjs.org/api/webpage/method/render.html</a><ul>
<li>PNG</li>
<li>GIF</li>
<li>JPEG</li>
<li>PDF</li>
</ul>
</li>
</ul>
<h3 id="rssg-js">rssg.js</h3>
<p>dosyamızın son hali bu şekilde olmalı</p>
<pre><code>var args = require(&#39;system&#39;).args;
var fs = require(&#39;fs&#39;);
var page = new WebPage();
if ( 1 === args.length ) {
console.log(&#39;Url addresi girmediniz&#39;);
phantom.exit();
}
var urlAddress = args[1].toLowerCase();
var viewports = [
{
width : 1200,
height : 800
},
{
width : 1024,
height : 768
},
{
width : 768,
height : 1024
},
{
width : 480,
height : 640
},
{
width : 320,
height : 480
}
];
page.open(urlAddress, function (status) {
if ( &#39;success&#39; !== status ) {
console.log(&#39;Adrese bağlanılamadı.&#39;);
} else {
var folder = urlToDir(urlAddress);
page.viewportSize = viewports[0];
var output = folder + &quot;/&quot; + getFileName();
console.log(&#39;Saving &#39; + output);
page.render(output);
}
phantom.exit();
});
function urlToDir(url) {
var dir = url
.replace(/^(http|https):\/\//, &#39;&#39;)
.replace(/\/$/, &#39;&#39;);
if ( !fs.makeTree(dir) ) {
console.log(&#39;&quot;&#39; + dir + &#39;&quot; oluşturulamadı.&#39;);
phantom.exit();
}
console.log(&#39;&quot;&#39; + dir + &#39;&quot; oluşturuldu.&#39;);
return dir;
}
function getFileName() {
var d = new Date();
var date = [
d.getUTCFullYear(),
d.getUTCMonth() + 1,
d.getUTCDate()
];
var time = [
d.getHours() &lt;= 9 ? &#39;0&#39; + d.getHours() : d.getHours(),
d.getMinutes() &lt;= 9 ? &#39;0&#39; + d.getMinutes() : d.getMinutes(),
d.getSeconds() &lt;= 9 ? &#39;0&#39; + d.getSeconds() : d.getSeconds(),
d.getMilliseconds()
];
return date.join(&#39;-&#39;) + &#39;_&#39; + time.join(&#39;-&#39;) + &quot;.png&quot;;
}
</code></pre><p>eğer herşey doğru ise ilk ekran görüntümüzü alalım.</p>
<h3 id="ilk-ekran-g-r-nt-s-">ilk ekran görüntüsü</h3>
<pre><code>phantomjs rssg.js https://nodejs-dersleri.github.io/
</code></pre><p><img src="/articles/phantomjs-ile-responsive-ekran-goruntusu-alma/ilk-ekran-goruntusu.png" alt="ilk-ekran-goruntusu"></p>
<p>klasörümüzde ise aşşağıdaki gibi bir ekran görüntüsü olması gerekiyor.
<img src="/articles/phantomjs-ile-responsive-ekran-goruntusu-alma/2015-11-22_22-03-19-449.png" alt="ilk-ekran-goruntusu"></p>
<p>Gördüğünüz gibi ekran görüntüsü hazır ama bir problem var viewports dizimizin ilk nesnesini gönderdik yani </p>
<pre><code>{
width : 1200,
height : 800
}
</code></pre><p>fakat çıktıda yükseklik 800px değil, aslında olması gereken sonuç tam olarakta bu;
viewports dediğimiz şey aslında bir nevi pencere boyutu yani 1200x800 bir çözünürlükte siteyi açtiğinizda sitenin Y eksininde sadece 800px’lik kısmını görüyorsunuz? hayır scroll yaparak tüm yükseklikte gezmeniz mümkün
burdaki sonuçta aynen bu.
bir sonraki yazımızda hem farklı boyutlarda hemde görüntüyü kırparak ve bunları paremetrelere dayalı olarak yapacağız.</p>
<hr>
</description>
</item>
<item>
<title>Npm modulleri - Chalk nedir?</title>
<link>http://nodejs-dersleri.github.io/articles/npm-moduleri-chalk-nedir/</link>
<pubDate>Fri, 06 Nov 2015 23:30:00 +0300</pubDate>
<guid isPermaLink="true">http://nodejs-dersleri.github.io/articles/npm-moduleri-chalk-nedir/</guid>
<author></author>
<description><p>Chalk, colors, cli-color modülleri aslında aynı işe yarıyor. Terminalde verdiğiniz çıktıları renklendirip font’ları ile farkındalık yaratabilirsiniz.</p>
<p>Aralarında bazı farklılıklar olsa da içlerinde hız, api bakımından en iyisi(benim için). İndirilme oranıda epey yüksek, 5700’den fazla <a href="https://www.npmjs.com/browse/depended/chalk">npm modülünde</a> kullanılmış.</p>
<hr>
<p><img src="/articles/npm-moduleri-chalk-nedir/npm-modulleri-chalk.svg" alt="Npm modulleri - Chalk nedir"></p>
<blockquote>
<p>Konuyu iki başlık altında inceleyeceğiz</p>
</blockquote>
<ol>
<li>Chalk’ın kullanılışı</li>
<li>Chalk gibi bir modül ya da util nasıl yapabiliriz.</li>
</ol>
<p></br></p>
<h3 id="package-json">package.json</h3>
<pre><code>{
&quot;name&quot;: &quot;chalk-module&quot;,
&quot;version&quot;: &quot;1.0.0&quot;,
&quot;main&quot;: &quot;index.js&quot;,
&quot;repository&quot; : {
&quot;type&quot; : &quot;git&quot;,
&quot;url&quot; : &quot;https://github.com/nodejs-dersleri/chalk&quot;
}
}
</code></pre><h3 id="index-js">index.js</h3>
<pre><code>
&#39;use strict&#39;;
/**
* Bağımlılıkları tanımlıyoruz
*/
var chalk = require(&#39;chalk&#39;);
/**
* Aşağıda Niteleyiciler, Renkler ve Arkaplan renklerini bulabilirsiniz
* Bir kaç örnekle başlayalım.
*/
console.log(
chalk.blue.bold(&#39;1. Nodejs için&#39;)
)
/**
* Inverse: atanan rengi tersine çevirir.
*/
console.log(
chalk.blue(&#39;2. Türkçe&#39;) + &#39; Kaynak&#39; + chalk.inverse.red(&#39;!&#39;)
)
/**
* birdern fazla niteleyici ve rengi ard arda kullanabilirsiniz
*/
console.log(
chalk.blue.magenta.dim.bold(&#39;3. Notlar&#39;)
)
console.log(
chalk.black(&#39;5. Örnek&#39;, chalk.underline.bgGreen(&#39; uygulamalar&#39;) + &#39;!&#39;)
)
console.log(
chalk.green(
&#39;Nodejs Dersleri &#39; +
chalk.blue.underline.bold(&#39;nodejs-dersleri.github.io&#39;) +
&#39; ziyaret edin&#39;
)
);
</code></pre><p>Şimdi terminalden <code>index.js</code> dosyamızı çağıralım.</p>
<pre><code>node index.js
</code></pre><p><img src="/articles/npm-moduleri-chalk-nedir/nodejs-chalk-nedir.png" alt="nodejs-chalk-nedir"></p>
<h3 id="niteleyiciler">Niteleyiciler</h3>
<ul>
<li><code>reset</code></li>
<li><code>bold</code></li>
<li><code>dim</code></li>
<li><code>italic</code> <em>(yaygın olarak desteklenmiyor)</em></li>
<li><code>underline</code></li>
<li><code>inverse</code></li>
<li><code>hidden</code></li>
<li><code>strikethrough</code> <em>(yaygın olarak desteklenmiyor)</em></li>
</ul>
<h3 id="renkler">Renkler</h3>
<ul>
<li><code>black</code></li>
<li><code>red</code></li>
<li><code>green</code></li>
<li><code>yellow</code></li>
<li><code>blue</code></li>
<li><code>magenta</code></li>
<li><code>cyan</code></li>
<li><code>white</code></li>
<li><code>gray</code></li>
</ul>