There are a number of ways to add direct full-text search of a ctext.org text to an external website. One of the most straightforward is to use the API “getlink” function to link to a text using its CTP URN. For example, to make a text box which will search this Harvard-Yenching copy of the 茶香閣遺草, you can first locate the corresponding transcribed text on ctext.org, go to the bottom-right of its contents page to get its URN (you need the contents page for the transcription, not the associated scan), which in this case is “ctp:wb417980” – this step can also be done programmatically by API if you want to repeat it for a large number of texts. Once you have the URN, you can create an HTML form which will send the URN and any user-specified search term to the ctext API, which will redirect the user’s browser to the search results. For example, the following HTML creates a search box for 茶香閣遺草:
<form action="https://api.ctext.org/getlink" method="get"> <input type="hidden" name="urn" value="ctp:wb417980" /> <input type="text" name="search" /> <input type="hidden" name="redirect" value="1" /> <input type="submit" value="Search" /> </form>
This will display the following type of search box (try entering a search term in Chinese and clicking “Search”):
You can also supply the optional “if” and “remap” parameters if you want users of your form to be directed to the Chinese interface, or to use the simplified Chinese version of the site (the defaults are English and traditional Chinese). For Chinese interface, between the <form … /> and </form> tags, add the following line:
<input type="hidden" name="if" value="zh" />
For simplified Chinese, add this line:
<input type="hidden" name="remap" value="gb" />
If you want to make a link to the text itself using the URN, you can also directly link to the API endpoint:
<a href="https://api.ctext.org/getlink?urn=ctp:wb417980&redirect=1">茶香閣遺草</a>
Live example: 茶香閣遺草
Again, the “if” and “remap” parameters can also be supplied to choose the interface used, as per the API documentation.