@@ -209,6 +209,86 @@ class JSONOutlineSchema
209209 }
210210 return false ;
211211 }
212+
213+ /**
214+ * Get an item by property value
215+ */
216+ getItemByProperty ( propName , value ) {
217+ for ( var id in this . items ) {
218+ if ( this . items [ id ] [ propName ] === value ) {
219+ return this . items [ id ] ;
220+ }
221+ }
222+ return false ;
223+ }
224+ /**
225+ * Filter based on a set of parents built recursively
226+ */
227+ findBranch ( id ) {
228+ const items = this . orderTree ( this . items ) ;
229+ let decendentIds = [ id ] ;
230+ let children = [ ] ;
231+ children . push ( this . getItemById ( id ) ) ;
232+ // walk items and find things that have parent as present id
233+ for ( var key in items ) {
234+ if ( decendentIds . includes ( items [ key ] . parent ) ) {
235+ children . push ( items [ key ] ) ;
236+ decendentIds . push ( items [ key ] . id ) ;
237+ }
238+ }
239+ return children ;
240+ }
241+
242+ findChildenRecursively ( items , activeIds = [ ] ) {
243+ for ( var key in items ) {
244+ // we found a kid
245+ if ( activeIds . includes ( items [ key ] . parent ) ) {
246+
247+ }
248+ let child = this . items [ key2 ] ;
249+ if ( child . parent == item . id ) {
250+ children . push ( child ) ;
251+ }
252+ }
253+ for ( var key in currentItems ) {
254+ let item = currentItems [ key ] ;
255+ if ( ! idList . includes ( item . id ) ) {
256+ idList . push ( item . id ) ;
257+ found . push ( item ) ;
258+ let children = [ ] ;
259+ for ( var key2 in this . items ) {
260+ let child = this . items [ key2 ] ;
261+ if ( child . parent == item . id ) {
262+ children . push ( child ) ;
263+ }
264+ }
265+ // sort the kids
266+ children . sort ( function ( a , b ) { return a . order - b . order } ) ;
267+ // only walk deeper if there were children for this page
268+ if ( children . length > 0 ) {
269+ this . orderRecurse ( children , sorted , idList ) ;
270+ }
271+ }
272+ }
273+ }
274+ /**
275+ * Get an item by ID
276+ */
277+ async getContentById ( id , cache = false ) {
278+ const item = this . getItemById ( id ) ;
279+ // @todo something is up with our page cache request engine and not returning data in prod
280+ /*if (cache && process.env.OPEN_APIS_ENV !== 'development') {
281+ return await fetch(`https://${process.env.VERCEL_URL}/api/apps/haxcms/pageCache?site=${this.file}&uuid=${id}&type=link`, this.__fetchOptions).then((d) => d.ok ? d.text() : '');
282+ }
283+ else {*/
284+ let location = this . file . replace ( this . __siteFileBase , item . location ) ;
285+ if ( this . __siteLocationPathName ) {
286+ location = location . replace ( this . __siteLocationPathName + '/' , '' ) ;
287+ }
288+ return await fetch ( location , this . __fetchOptions ) . then ( ( d ) => d . ok ? d . text ( ) : '' ) ;
289+ //}
290+ }
291+
212292 /**
213293 * Save data back to the file system location
214294 */
0 commit comments