Sistem File Antarplanet - Blog IPFS Sederhana Menggunakan XSLT

Ada masalah: Situs di IPFS tidak memiliki kemampuan untuk menggunakan skrip sisi server untuk membentuk halaman. Jika Anda menggunakan pembuatan halaman sebelum memuat, lalu menambahkan item menu baru ke setiap halaman, kami akan mengubah hash dari halaman-halaman ini. Jadi seluruh perakitan halaman harus dilakukan oleh browser.


Biasanya membentuk konten halaman menggunakan JavaScript. Ini adalah teknologi yang akrab, tetapi memiliki kelemahan.


Saya akan menggunakan XSLT. Ini adalah teknologi templat kuno yang telah lama dibangun di peramban tetapi hanya sedikit yang menggunakannya. Mungkin karena template membuat Anda menulis banyak teks karena kebingungan dengan ruang nama dan banyak kesalahan tanpa penjelasan yang jelas. Selain itu, meskipun sudah ada XSLT 3.0 di browser, hanya XSLT 1.0 yang masih tersedia.


XSLT berfungsi seperti ini:


  1. Seorang pengguna membuka dokumen XML di browser.
  2. Di header XML, dokumen berisi tautan ke template XSLT.
    <?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
  3. Templat di browser yang didasarkan pada dokumen XML dan data lainnya membentuk dokumen xHTML.
  4. Browser menampilkan dokumen xHTML yang dihasilkan.

Dengan menautkan banyak halaman ke satu templat, Anda dapat mengubah dokumen xHTML yang ditampilkan tanpa mengubah dokumen XML. Jadi, ketika mengubah desain, hash dokumen XML tidak akan berubah, yang berarti bahwa salinan lama mereka akan menjadi sumber untuk yang baru di IPFS.


. XML .


gambar



XML . XML HTML:


  1. .
    <br />.
  2. . .
    <>
        < />
        <- />
        <-- />
    </>
  3. .
    <>
         
    </>

.xml


.


XML - :
: ' .xml'


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
<>
    <></>
    <>
        <></>
    </>
</>
<!--         -->

. . meta description. .


xHTML ( HTML ) .


:


: 'Lorem Ipsum.xml'
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
<>
    <>Lorem Ipsum</>
    <>
<h1>Lorem ipsum dolor sit amet</h1>

<>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras feugiat orci non orci tincidunt molestie. Donec eget porta metus. Aenean malesuada nunc lacus, a sollicitudin neque fermentum eu. <b style="color: green">Vestibulum egestas viverra urna</b>, sit amet mollis ipsum commodo imperdiet. Quisque sit amet est eu nibh commodo pharetra.</> Donec fermentum nisi nec lorem auctor imperdiet. Morbi ultricies at magna ullamcorper malesuada. In eget arcu dapibus, vehicula nunc vel, convallis erat. Cras accumsan lacus vel tellus gravida, eu gravida turpis congue. In ultrices pellentesque odio at hendrerit.

<h1>Cras nec lorem facilisis</h1>

Cras nec lorem facilisis justo porttitor scelerisque id id ipsum. Duis mattis, sem eu sollicitudin pharetra, diam augue ullamcorper nisl, id dictum turpis ex in nisl. Aliquam venenatis egestas urna eget porttitor. Suspendisse potenti. Curabitur fermentum fermentum nulla, a lobortis ipsum laoreet eget. Duis finibus lacus id tempor elementum. <i>Interdum et malesuada fames ac ante ipsum primis in faucibus</i>. Curabitur tempus eget turpis ut tincidunt. In quis massa et risus tempor luctus quis eu enim. Duis finibus sem sit amet elit scelerisque molestie. Suspendisse laoreet, leo ut accumsan dapibus, nisi tellus dignissim lorem, eu auctor tellus diam vel nisi. Donec sem tortor, suscipit a leo maximus, aliquet dapibus nisl. Integer sodales, dui ut vulputate pharetra, ipsum neque tempor ipsum, sed porta tortor quam a nisl.

Sed consequat purus sed porttitor pulvinar. Mauris sollicitudin non sem a malesuada. Vestibulum non velit finibus, elementum purus nec, aliquam lacus. Etiam leo enim, venenatis id luctus ut, ornare sit amet ex. Nunc vel fringilla ante. Cras lobortis scelerisque pulvinar. Ut lectus augue, viverra quis molestie eu, maximus nec leo. <u>Sed facilisis odio ut malesuada mollis</u>. Pellentesque enim lacus, luctus nec velit quis, scelerisque tincidunt magna. Proin laoreet, erat eget porttitor bibendum, odio augue suscipit purus, id commodo magna nibh sed est. Ut dignissim aliquet sem, id suscipit sapien mollis volutpat. Vivamus ac fringilla est, at sagittis diam.
    </>
</>

.xhtml


xHTML XSLT . . XSLT .


xHTML XML.


: 'xhtml/.xhtml'


<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <!--   <>     title    -->
        <title class="">   XML</title>
        <meta  class=""/>
        <!--       HTML -->
        <style>
            /*   xHTML    */

            .{
                white-space: pre-wrap;
            }

            /*       */

              . h1, . h2
            , . h3, . h4
            , . h5, . h6 {
                display: inline;
            }
        </style>
    </head>
    <body>
        <!--           -->
        <ul   class="" />
        <h1   class="" />
        <span class=""> <b style="color: red"><![CDATA[<></>]]></b>   .  .</span>
    </body>
</html>

.xslt


(XML xHTML) XSLT.


'.xhtml' XML. XML xHTML.


: 'xslt/.xslt'


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!--
                '.xslt'
              
        Chrome     URL   URL
    -->
    <xsl:include href="%D0%BD%D0%B0%D0%B2%D0%B8%D0%B3%D0%B0%D1%86%D0%B8%D1%8F.xslt" />

    <!--      xHTML     XML -->
    <xsl:output method="xml" encoding="UTF-8"/>

    <!--        -->
    <xsl:variable name="" select="" />

    <!--     '.xhtml' -->
    <xsl:template match="/">
        <!-- mode            -->
        <xsl:apply-templates mode="xhtml" select="document('../xhtml/%D0%B7%D0%B0%D0%BF%D0%B8%D1%81%D1%8C.xhtml')" />
    </xsl:template>

    <!--        -->
    <xsl:template mode="xhtml" match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates mode="xhtml" select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <!--         '.xhtml' -->

    <!--   match    Firefox -->

    <!--    ''     '' -->
    <xsl:template mode="xhtml" match="*[contains(@class, '')]">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates mode="xml" select="$////node()" />
        </xsl:copy>
    </xsl:template>

    <!--   meta    '' -->
    <xsl:template mode="xhtml" match="xhtml:meta[contains(@class, '')]">
        <meta name="description" content="{$///}" />
    </xsl:template>

    <!--       -->
    <xsl:template mode="xhtml" match="*[contains(@class, '')]">
        <!--       '.xsl' -->
        <xsl:call-template name="" />
    </xsl:template>

    <!--    ''     '' -->
    <xsl:template mode="xhtml" match="*[contains(@class, '')]">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:value-of select="$/" />
        </xsl:copy>
    </xsl:template>

    <!--    ''     '' -->
    <xsl:template mode="xhtml" match="*[contains(@class, '')]">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates mode="xml" select="$//node()" />
        </xsl:copy>
    </xsl:template>

    <!-- 
              xml 

              
        (   svg )  
     -->
    <xsl:template mode="xml" match="*[namespace-uri()]|@*">
        <xsl:copy>
            <xsl:apply-templates mode="xml" select="node()|@*" />
        </xsl:copy>
    </xsl:template>

    <!--       -->
    <xsl:template mode="xml" match="*">
        <!--
                 .    
                 
        -->
        <xsl:element name="{name()}">
            <xsl:apply-templates mode="xml" select="node()|@*" />
        </xsl:element>
    </xsl:template>

    <!--    ''    -->
    <xsl:template mode="xml" match="">
        <xsl:apply-templates mode="xml" select="node()|@*" />
    </xsl:template>

    <!--      xHTML  --> 
    <xsl:template mode="xml" match="h1|h2|h3|h4|h5">
        <!-- 
            h1       '' 
               xHTML  
        -->
        <xsl:element name="h{substring(name(), 2, 1) + 1}">
            <!--          id     -->
            <xsl:attribute name="id">
                <xsl:value-of select="." />
            </xsl:attribute>
            <xsl:apply-templates mode="xml" select="node()|@*" />
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>


. .


.xml


XML :


: '.xml'


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
<>
    <> </>
</>
<!--         -->

'' xml .


:


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
<>
    <>Lorem Ipsum 1</>
    <>Lorem Ipsum 2</>
</>


'.xml' xHTML .


: 'xslt/.xslt'


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!--      '.xsl' -->
    <xsl:template name="">
        <ul>
            <!--   -->
            <xsl:copy-of select="@*" />

            <!--     '.xml'   -->
            <xsl:apply-templates mode="" select="document('../%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB.xml')//" />
        </ul>
    </xsl:template>

    <!--       -->
    <xsl:template mode="" match="">
        <li>
            <a href="{text()}.xml">
                <xsl:value-of select="text()" />
            </a>
        </li>
    </xsl:template>

</xsl:stylesheet>

.



.


index.html


IPFS index.html. XML .


'.xml'.


: 'index.html'


<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <!--     '.xml' -->
        <!-- Firefox      url   -->
        <meta http-equiv="refresh" content="0; url=%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB.xml" />
    </head>
    <body>
        <!--        -->
         :
        "<a class="" href=".xml"></a>"
    </body>
</html>

HTML . XML HTML . .


.xslt


'.xml' '.xslt'. '.xml' 'index.html' .


: 'xslt/.xslt'


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" encoding="UTF-8"/>

    <xsl:variable name="" select="//text()" />

    <xsl:template match="/">
        <!--       -->
        <xsl:apply-templates mode="html" select="document('../index.html')" />
    </xsl:template>

    <!--     -->
    <xsl:template mode="html" match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates mode="html" select="node()|@*" />
        </xsl:copy>
    </xsl:template>

    <!--    -->

    <!--     -->
    <xsl:template mode="html" match="xhtml:meta[@http-equiv='refresh']">
        <!--
             
             1.   URL
                      URL
        -->
        <base href="{$}.xml" />

        <!-- 2.   -->
        <meta http-equiv="refresh" content="0; url=#" />
    </xsl:template>

    <!--         -->
    <xsl:template mode="html" match="xhtml:a[@class='']">
        <a href="" class="{@class}">
            <xsl:value-of select="$" />
        </a>
    </xsl:template>

</xsl:stylesheet>

'.xslt' .



  1. '.xml' :


    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
    <>
        <>  </>
    </>

  2. ' .xml' ' .xml'


  3. :


    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet href="xslt/.xslt" type="text/xsl" ?>
    <>
        <>  </>
        <>
       .
        </>
    </>


.



IPFS .


Firefox


  1. about:config security.fileuri.strict_origin_policy false

Chrome


  1. --allow-file-access-from-files

IPFS


.


ID


.


ipfs key gen -t rsa blog

ID



  1. ipfs


    ipfs add -r -s rabin --inline --raw-leaves --fscache < >

    -r
    -s rabin — jpeg, mp3 .
    --inline — .
    --raw-leaves--nocopy .
    --fscache — .


  2. ID .


    ipfs name publish -k blog <>



:


http://127.0.0.1:8080/ipfs/<>
http://127.0.0.1:8080/ipns/<id >

:


http://gateway.ipfs.io/ipfs/<>
http://gateway.ipfs.io/ipns/<id >

. ID .


.



Secara alami, desain dan fungsionalitas blog ini dapat dan harus dikembangkan untuk memenuhi kebutuhan pengguna. Saya menetapkan beberapa dasar untuk dikembangkan lebih lanjut.


Referensi


Referensi yang baik pada
kode XSLT GitHub ( snapshot )


All Articles